1179 posts
  • Has referred 200+ members
  • Has sold $10,000+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Sells items exclusively on Envato Market
+2 more
mabuc says

Hello,

I have a cpt services and each post I added exclude checkbox. My question/problem is how can I get the checkbox exclude value in a loop using a new wp_query? below are the code I used..

$args = array( 'post_type' => 'gallery', 'post__not_in' => array($exclude_id), 'paged' => $paged );
$wp_query = new WP_Query( $args );

$exclude = get_post_meta( $wp_query->post->ID, "exclude", true );
if($exclude == "on") {
   $exclude_id = $wp_query->post->ID;
}

I want to get the $exclude_id value and add it in the $args statement but it’s not working.. can anyone help me with this..

thank you very much!

117 posts
  • Has been part of the Envato Community for over 3 years
  • Has sold $100+ on Envato Market
  • Has collected 1+ items on Envato Market
  • Sells items exclusively on Envato Market
+1 more
fAntasticmE says
you better use it in the loop with an if statement
if(!get_post_meta(post->ID, "exclude",true)){
//do stuff
}
1179 posts
  • Has referred 200+ members
  • Has sold $10,000+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Sells items exclusively on Envato Market
+2 more
mabuc says

you better use it in the loop with an if statement
if(!get_post_meta(post->ID, "exclude",true)){
//do stuff
}

that won’t work. It should be

if(get_post_meta( $post->ID, "exclude", true )) { } 
I used this before but I am adding a dynamic class=”last” if it’s 2 cols, 3 cols and 4 cols.. so I decided to add the exclude in the $arg statement…
by
by
by
by
by
by