这是情况,我有一个名为Skill的自定义税.我希望能够只显示技能设置为英语的日语.
我正在尝试学习如何使用pre_get_posts钩子来修改我的get_posts查询.这是我的例子,但是我遇到了错误:
注意:未定义的变量:postdata
这是我根据研究尝试的:
add_filter( 'pre_get_posts', 'wpshout_fundraiser_recent_posts' );
function wpshout_fundraiser_recent_posts( $query ) {
// Fetch only posts tagged with "Japanese from English"
$taxquery = array(
array(
'taxonomy' => 'Japanese from English',
'field' => 'skill',
'terms' => array( 'skill' ),
)
);
$query->set( 'tax_query', $taxquery );
Run Code Online (Sandbox Code Playgroud)
我确信上面的查询有问题,我不完全理解.任何帮助,请解释如果可能的话阵列的每个字段.
小智 5
试试下面的代码,这应该工作,
add_filter( 'pre_get_posts', 'wpshout_fundraiser_recent_posts' );
function wpshout_fundraiser_recent_posts( $query ) {
$posts_array = get_posts(
array(
'posts_per_page' => -1,
'post_type' => 'Your Post Type Name',
'tax_query' => array(
array(
'taxonomy' => 'Japanese from English',
'field' => 'skill',
'terms' => array( 'skill' ),
)
)
)
);
return $posts_array;
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
174 次 |
最近记录: |