我使用插件来选择使用'pre_get_posts'过滤帖子的精选帖子。它在正常的query_post()中工作正常,但它在ajax中不起作用。这是我的代码
<?php
add_action('wp_ajax_portscroll', 'portscroll');
add_action('wp_ajax_nopriv_portscroll', 'portscroll');
function portscroll(){
?>
<?php
$offset_click= $_POST['data'];
$offset= 4+$offset_click*2;
$args = array(
'post_type' => 'portfolio',
'posts_per_page' => 2,
'featured' => 'yes',
'orderby' => 'menu_order',
'order' => 'ASC',
'offset'=> $offset
);
$post_osrtfolios = query_posts($args);
if ($post_osrtfolios) :
foreach ($post_osrtfolios as $post_osrtfolio) :
///contents goes here
endforeach;
endif;
wp_reset_query();
} ?>
一切正常,查询工作正常,但参数'featured'=&gt; '是'不起作用。此参数来自plugin。
答案 0 :(得分:-1)
$args = array(
'post_type' => 'portfolio',
'posts_per_page' => 2,
'meta_query' => array(
array(
'key' => '_is_featured',
'value' => 'yes'
)
),
'orderby' => 'menu_order',
'order' => 'ASC',
'offset'=> $offset
);
使用此