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…

Helpful Information

  • Please read our community guidelines. Self promotion and discussion of piracy is not allowed.
  • Open a support ticket if you would like specific help with your account, deposits or purchases.
  • Item Support by authors is optional and may vary. Please see the Support tab on each item page.

Most of all, enjoy your time here. Thank you for being a valued Envato community member.

Post Reply

Format your entry with some basic HTML. Read the Full Details, or here is a refresher:

<strong></strong> to make things bold
<em></em> to emphasize
<ul><li> or <ol><li> to make lists
<h3> or <h4> to make headings
<pre></pre> for code blocks
<code></code> for a few words of code
<a></a> for links
<img> to paste in an image (it'll need to be hosted somewhere else though)
<blockquote></blockquote> to quote somebody

:grin: :shocked: :cry: Complete List of Smiley Codes

by
by
by
by
by
by