开发者

WP_Query + $query_vars + custom field

I have custom post type items in my theme. They represent projects in portfolio. I have a custom field checkbox that sets the option "Featured" for every single project. So, when the project is featured, it's being shown on the main page of the site. If the "Featured" checkbox is unset, the project is visible only on the portfolio page. What I need now is to query only featured projects to s开发者_Python百科how them on the main page. I use this code to show the posts but I don't know how to add the option to get only posts with the "Featured" custom field set to True.

$args = array(
        'post_type' => 'project',
        'post_status' => 'publish');
    $projects = new WP_Query($args);
    if ($projects->have_posts()) {
        while ($projects->have_posts())
... Show the project info here

What can I do about this?


Add this to your array.

   meta_key => 'featured',
   meta_value => 'true'
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜