Home Forums Front-end Issues Meta_compare with true/false field


Meta_compare with true/false field

  • Hi ACF,

    Im really happy with your plugin. It saves me loads of work

    I have added a true/false field to a post. From a custom loop i want to exclude every post that has that option checked (meaning true).

    I have been trying for hours but i cant get it to work. I tried this code:

    <?php query_posts( array(
    	'showposts' => 10,
    	'meta_query' => array(
    			'key' => 'xv_agenda',
    			'value' => '1',
    			'compare' => '!='
    <?php if (have_posts()) : ?>		
    <?php while (have_posts()) : the_post(); ?>

    What am i doing wrong?

    The field name is xv_agenda, and when the checkbox is checked i want to exclude it from my loop. Can you guys help me with this?

    Thanks in advance!

    Cheers Rhodo

  • Hi @tienvijf

    Your code looks good.

    Have you done any debugging of the data which is queried?


  • Hi Elliot,

    Thanks for your time.

    I dont have any idea how to do that since im not a programmer.
    All that happens when i fiddle with the options above is that i see the post i dont want to or i dont see any.

    What would you suggest i should do?



  • Hi @tienvijf

    I highly suggest taking a few minutes to research PHP debugging techniques such as print_r.

    Then debug your code line by line to fin dout at which point it is not as expected.


  • Hi I had the exact same issue, and I know the original post was a couple months ago, but for future voyagers…

    The solution for me turned out to be the issue with adding new custom fields to existing posts. The posts need to be updated, even if the custom field value is unchanged from the default.

  • I am in a similar situation. I have added a true/false checkbox to existing fields and it doesn’t recognize an unchecked value as 0. When I echo the value of a checked box I get 1 and an unchecked box returns nothing. I have tried the bulk update posts to try to get the database to recognize this new fields and record a 0 but it doesn’t seem to work.

    I have been working through this on another post
    but I have not had any success. I know the code makes sense but the results don’t display.

    I’d love to know what you did to resolve this issue.

Viewing 6 posts - 1 through 6 (of 6 total)

The topic ‘Meta_compare with true/false field’ is closed to new replies.