WordPress.org

Ready to get started?Download WordPress

Forums

WP_Query with meta_query (4 posts)

  1. snive
    Member
    Posted 2 years ago #

    I'm trying to list post with different custom fields

    my args looks like this:

    $args = array(
     	                                'post_type' => 'post',
     	                                'meta_query' => array(
    		                                'relation' => 'AND',
     		                                array(
     			                                'key' => 'ACF_type',
    			                                 'value' => $t,
    			                                 'compare' => 'LIKE'
     		                                ),
     		                                array(
     			                                'key' => 'ACF_sex',
     			                                'value' => $s,
     			                                'compare' => 'LIKE'
     		                                )
     	                                )
                                      );

    And that works but I realy whant to use 'compare' => '=' but when change to this no post are listed
    I've tried with string,char and numeric but nothing shows when I use '='

    What am I doing wrong?

  2. keesiemeijer
    moderator
    Posted 2 years ago #

    That's strange. And when you remove 'compare' from the array? The default value is '=', so you don't really need it. Try also with this 'relation' => 'OR'

  3. snive
    Member
    Posted 2 years ago #

    Yes I think it's strange
    I've tried to use OR and then I get more hits but I whant to use AND to only show post with the both values

    I'm using Advanced Custom Fields plugin to add this different custom fields but that schould not be the problem because I can use the custom fields like normal fields

  4. keesiemeijer
    moderator
    Posted 2 years ago #

    try
    - deactivating all plugins to see if this resolves the problem? If this works, re-activate the plugins one by one until you find the problematic plugin(s).

    - switching to the default theme to rule out any theme-specific problems.

Topic Closed

This topic has been closed to new replies.

About this Topic