最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

wp query - Get posts by meta value except one post

programmeradmin4浏览0评论
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 question

I 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 question

I 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
Add a comment  | 

1 Answer 1

Reset to default 2

If 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.

发布评论

评论列表(0)

  1. 暂无评论