如何使用wp_reset_query重置查詢?

wp_reset_query() 函式用於重置WordPress的查詢。在自定義查詢或修改查詢引數之後,你可能需要使用這個函式來重置到預設的查詢。例如:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
// 自定義查詢
$args = array(
'post_type' => 'product',
'posts_per_page' => 10,
);
$custom_query = new WP_Query($args);
// 重置查詢
wp_reset_query();
// 自定義查詢 $args = array( 'post_type' => 'product', 'posts_per_page' => 10, ); $custom_query = new WP_Query($args); // 重置查詢 wp_reset_query();
// 自定義查詢  
$args = array(  
    'post_type' => 'product',  
    'posts_per_page' => 10,  
);  
$custom_query = new WP_Query($args);  
  
// 重置查詢  
wp_reset_query();
未能解決您的問題?

請提交 聯絡工單