I have a custom field 'exclude' and the value would be a particular post, let's say 2124. Within the array I want to then call this custom field for the exclude => field but is this even possible?
-
What are you excluding this post from? From being displayed on your site? Can you provide us with what you have so far? – RachieVee Nov 14 '14 at 17:58
-
I've got a few pages where a list of posts are pulled in. And it's being excluded solely from that page. – Lewis Nov 14 '14 at 17:59
-
So on specific page, you want to exclude certain posts from showing? Why not use a category you can check off on posts you want to exclude and an is_page conditional. Then on your loop, you can check what page it is, and if it's that page, exclude posts from that category - assuming you have the same loop on other pages and just want to adjust the loop on this specific page. If that sounds like it'll work for you, I can provide some code as an answer. codex.wordpress.org/Function_Reference/is_page – RachieVee Nov 14 '14 at 18:02
-
Basically I have a custom page type created and within that page template I have the normal array to get a list of the posts. Within the array I have exclude => '', Obviously I can't put php the_field ('exclude_field') in the quotation marks to pull in the custom field that specifies the ID of the post(s) I want to exclude with 'exclude_field' being the name of the custom field. But is there a way to make this work? – Lewis Nov 14 '14 at 18:06
-
3edit your question, add more detail and your code. – Milo Nov 14 '14 at 18:06
Your question is pretty vague and you haven't given any example code, but the following may work for you:
<?php
global $post;
// Arguments
$args = array('
/* Enter your arguments in here... */
');
// The query
$the_query = new WP_Query( $args );
// The loop
if ( $the_query->have_posts() ) {
// Exclude ID
$exclude_id = get_post_meta( $post->ID, 'exclude_field', true );
while ( $the_query->have_posts() && $post->ID !== $exclude_id ) {
$the_query->the_post();
/*
Output here, e.g.
echo '<h2>' . get_the_title() . '</h2>';
echo '<div>' . get_the_content() . '</div>';
*/
}
}
?>