Php 在wordpress文件中将数据库查询放在哪里?

Php 在wordpress文件中将数据库查询放在哪里?,php,wordpress,Php,Wordpress,我试图在wordpress站点中放置以下查询,我应该将此查询放置在何处?我应该为常规数据库查询创建插件还是有其他方法。我试图在我的模板中获得各种查询的结果 $pop = $wpdb->get_results("SELECT id, post_title,FROM posts WHERE post_type='post' ORDER BY comment_count DESC LIMIT 10"); foreach($pop as $post) : ?> <li>

我试图在wordpress站点中放置以下查询,我应该将此查询放置在何处?我应该为常规数据库查询创建插件还是有其他方法。我试图在我的模板中获得各种查询的结果

$pop = $wpdb->get_results("SELECT id, post_title,FROM posts WHERE post_type='post' ORDER BY comment_count DESC LIMIT 10");  
 foreach($pop as $post) : ?>  
 <li> <?php echo $post->post_title; ?> </li>  
 <?php endforeach; ?> 
$pop=$wpdb->get_results(“选择id,post_title,从post_type='post'按注释排序的post_count DESC LIMIT 10”);
foreach($pop作为$post):?>

  • 您可以将此查询放在themes functions.php文件中:

    $pop = $wpdb->get_results("SELECT id, post_title,FROM posts WHERE post_type='post' ORDER BY comment_count DESC LIMIT 10");  
    foreach($pop as $post) : ?>  
         <li> <?php echo $post->post_title; ?> </li>  
    <?php endforeach; ?> 
    
    $pop=$wpdb->get_results(“选择id,post_title,从post_type='post'按注释排序的post_count DESC LIMIT 10”);
    foreach($pop作为$post):?>
    
  • 如果您将查询放入任何Wordpress核心文件中,当您将Wordpress更新到最新版本时,您所做的更改将丢失

    希望这有帮助:)