Closed. This question needs to be more focused. It is not currently accepting answers.admin管理员组文章数量:1327804
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this questionI have a meta_key
with name director
in my posts and i tried to show all posts with some value like christian bale
in director meta_key
, i want to use this query in single.php and not showing Current post in new query
Thanks for any help
Closed. This question needs to be more focused. It is not currently accepting answers.Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this questionI have a meta_key
with name director
in my posts and i tried to show all posts with some value like christian bale
in director meta_key
, i want to use this query in single.php and not showing Current post in new query
Thanks for any help
Share Improve this question edited Jul 27, 2020 at 19:49 alam7o asked Feb 28, 2017 at 12:37 alam7oalam7o 317 bronze badges 1- You can create common category for both of them and then assign to both .Check condition when displaying post that christan bell category is aasigned to movie posttype and then call that all movie posts that are in same category. – Sonali Commented Feb 28, 2017 at 12:56
1 Answer
Reset to default 2If you want to get the post for an actor for example, there is different solutions, but in my opinion, the best is to use tag
as actors names, or post meta
. The current solution I give to you is using WordPress search system and try to find posts.
// We try to get post for Christian bale as a keyword
$args = array(
'post_type' => 'post',
'post__not_in' => array(get_the_ID()), // We don't need the current post
's' => 'christian bale', // We put the Christian Bale search here
);
// Or as a meta value
$args = array(
'post_type' => 'post',
'post__not_in' => array(get_the_ID()), // We don't need the current post
'meta_key' => 'director',
'meta_value' => 'christian bale',
);
$films = new WP_Query($args);
// If there's posts, show it
if($films->have_posts())
{
while($films->have_posts())
{
$films->the_post();
the_title();
the_content();
}
}
// Reset query
wp_reset_query();
Using this after your post, or in your post will allow you to show post containing "christian bale" text.
本文标签: wp queryGet posts by meta value except one post
版权声明:本文标题:wp query - Get posts by meta value except one post 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742228159a2436714.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论