adding multiple parameters to an if statement
-
Oh, I’m not too sure how to explain this so I’ll just come out with it;
If I can exclude a post ID that matches a wp_query, can I add a meta_value parameter too?
My site displays a featured post on the index and beneath that 3 recent posts.
Featured code looks like this
$featured = new WP_Query(); $featured->query('showposts=1&meta_value=featured'); while($featured->have_posts()) : $featured->the_post(); $wp_query->in_the_loop = true; $featured_ID = $post->ID;Once that’s done and it comes to the 3 recent posts this if statement makes sure that the featured_ID defined above isn’t displayed
if ($post->ID != $featured_ID) { ?>This works fine, but say in the future I create another featured post within 2 posts of the last one, the older one will display in the recent posts since it no longer has the featured_ID, and I don’t want that.
So using the if statement will it be possible to make sure that anything with meta_value=featured is also not displayed?
Thanks in advance
-
I’ve been trying to get this to work and I think the way to achieve this is to exclude either a meta_key or value from the first query on the index page:
<?php query_posts("showposts=4"); ?> <?php $first = true; ?> <?php if(have_posts()) : while(have_posts()) : the_post(); ?> <? if ($post->ID != $featured_ID) { ?>However, after reading the query codex, I can only add, not exclude.
Example reading the codex, I’m pretty sure this should work:
<?php query_posts("showposts=4&meta_compare= !=&meta_key=featured"); ?>But it doesn’t. The value for the featured key is ‘yes’ but even changing it to &meta_value=yes has no effect
Can someone please shed some light on this, it’s driving me mad.
The topic ‘adding multiple parameters to an if statement’ is closed to new replies.