自定义查询无法在Wordpress页面中工作?

时间:2022-03-31 16:38:44

This is page of wordpress I am adding core php code for displaying data into table as per select input for that I am using javascript for gettin input and pass to the page page.And that page getting value as per value fir a mysql query.But my core php code dispaly as it is on screen. I am not able to understand how to do this. Beacuse I am new in wordpress Today is my first day in wordpress. Please help me ..Thanks in advance

这是wordpress的页面我正在添加核心php代码,用于根据选择输入将数据显示到表中我使用javascript进行gettin输入并传递到页面页面。并且该页面按值获取值为一个mysql查询。但是我的核心PHP代码显示在屏幕上。我无法理解如何做到这一点。因为我是wordpress的新手今天是我在wordpress的第一天。请帮帮我..谢谢

    <?php
            $var=$_COOKIE['v'];
        $id = explode(",", $var);
            echo 'hawno:'.$id[1];
           $conn = mysql_connect("localhost", "root", "");
    $db = mysql_select_db("shepherddb");
    $err = error_reporting(E_ALL && ~E_NOTICE);
    $result=mysql_query("select              ship_id,track_id,track_ship_id,track_mod_of_transport,track_location,track_status from 
tracking,shipment");
while($data = mysql_fetch_array($result)) {
        print_r($data);
}   
    ?>

1 个解决方案

#1


0  

You need to use $wpdb global object provided by wordpress.

您需要使用wordpress提供的$ wpdb全局对象。

For example ,

例如 ,

global $wpdb;

$results = $wpdb->get_results( 'SELECT * FROM wp_options WHERE option_id = 1', OBJECT );

$ results = $ wpdb-> get_results('SELECT * FROM wp_options WHERE option_id = 1',OBJECT);

You can also use pre_get_posts action to modify the POSTS Query.

您还可以使用pre_get_posts操作来修改POSTS查询。

add_action( 'pre_get_posts', 'your_theme_function' );

Let me know if you need more information on the same.

如果您需要更多相关信息,请与我们联系。

#1


0  

You need to use $wpdb global object provided by wordpress.

您需要使用wordpress提供的$ wpdb全局对象。

For example ,

例如 ,

global $wpdb;

$results = $wpdb->get_results( 'SELECT * FROM wp_options WHERE option_id = 1', OBJECT );

$ results = $ wpdb-> get_results('SELECT * FROM wp_options WHERE option_id = 1',OBJECT);

You can also use pre_get_posts action to modify the POSTS Query.

您还可以使用pre_get_posts操作来修改POSTS查询。

add_action( 'pre_get_posts', 'your_theme_function' );

Let me know if you need more information on the same.

如果您需要更多相关信息,请与我们联系。