Support » Fixing WordPress » Can I Exclude Posts with Custom Field Names/Values?

  • I’ve created a custom field called ‘Snippet’ (and have created three different values, each post can belong to one of these three values) which I’ve applied to certain posts/news items (just the small news items on my site). I’ve got all these snippets to appear in my side bar using the excellent ‘Query Posts’ plugin.

    I don’t want any of these posts to appear in the main loop however and I’m struggling to work out how to do this. Can you filter out posts by using custom fields? I tried the below (in bold) but it didn’t work:

    $the_query = new WP_Query(‘meta_key=-Snippet&cat=-‘. $ex_feat . ‘,-‘ . $ex_vid . ‘,-‘ . $ex_aside . ‘&showposts=’ . $showposts . ‘&orderby=post_date&order=desc’);

    Am I going about this the correct way?

Viewing 1 replies (of 1 total)
  • One way to do it, if you are willing to do the extra work up front, would be to create a post category called snippet. When you assign a snippet to a post, also assign it to the snippet category. wp_query/query_posts easily excludes a category from a query.

    I see you have this available also

    Custom Field Parameters
    Retrieve posts (or Pages) based on a custom field key or value.
        * meta_compare= - operator to test the meta_value=, default is '=', with other possible values of '!=', '>', '>=', '<', or '<='

    you could try it out and see if a test like meta_compare<=’ ‘ would accomplish what you want – instead of trying to exclude, that would be what to include.

Viewing 1 replies (of 1 total)
  • The topic ‘Can I Exclude Posts with Custom Field Names/Values?’ is closed to new replies.