• Hi everybody,

    I’m struggling for hours now with the following problem. What I’m trying to do is ‘exclude reduced items from a wp-query array’

    This is the code I allready have:

    echo View::render('page-home.twig', array(
     'wp_query' => $wp_query,
     'posts' => aviators_properties_get_most_recent(4),
     'meta_key' => '_property_reduced',
     'meta_compare' => '!=',
     'meta_value' => true
       )
    );

    I know that the meta_key and meta_value is right. The first three lines is a part of the template which I use. So this is right too. But I’m not sure about the rest.

    I tried several alternatives like: meta_compare IN / NOT IN / EXISTS / NOT EXISTS / = / LIKE

    I also tried to put the meta things in an extra array. Like this:

    echo View::render('page-home.twig', array(
     'wp_query' => $wp_query,
     'posts' => aviators_properties_get_most_recent(4),
     'meta_query' => array(
            array(
            'meta_key' => '_property_reduced',
            'meta_compare' => '!=',
            'meta_value' => true
        )
       )
      )
    );

    All of this doesn’t work. Nothing changes at all.

    The page where I’m working on is:https://www.theoquaedackers.nl/test At the bottom of this page you see ‘recent toegevoegd’ In this array I want to exclude reduced items.

    Does anyone know what I’m doing wrong?

    Greets Mark

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator bcworkz

    (@bcworkz)

    Your first attempt should have sufficed, except that instead of true, you probably need 'true', a string value, not a boolean value. The datatype for meta values is longtext, not mixed. As such, watch for case, because true==True but 'true'!='True'

    Thread Starter Markgoessens

    (@markgoessens)

    Hi bcworkz,

    Thanks for your reply. I put the first code back and changed the meta value to ‘true’ or “true”
    But infortunitaly, this doesn’t work either. I don’t know what you mean with the last sentence. I tried ‘True’ with capital ‘t’ also.
    I also tried == instead of !=
    But all of these combinations won’t work.

    It’s very strange. Because there is another page on this website which uses this array:

    $properties = array(
    'post_type' => 'property',
    'posts_per_page' => aviators_settings_get_value('properties', 'properties', 'per_page'),
    'paged' => $paged,
    'tax_query' => array(),
    'meta_query' => array(
    	array(
    		'key' => '_property_reduced',
    		'value' => true,
    		'compare' => 'NOT EXISTS',
    		),
    	array(
    		'key' => '_property_featured',
    		'value' => true,
    		'compare' => 'NOT EXISTS',
    		)
    	)
    );

    And that works on that page. Of course I also tried ‘NOT EXISTS’, like on that other page, but this don’t work in this case.

    Moderator bcworkz

    (@bcworkz)

    Yeah, I guess it wouldn’t matter what type true is in PHP, I’m more conscious of type than need be, coming from strongly typed languages.

    It may be the View::render() method does not fully support WP_Query arguments. If it did, your query arguments should work. I’m sure if you did a new WP_Query using those arguments, the correct results would be returned. But I’ve no idea what View::render() does with such arguments. I take it this is some sort of theme method? I’ve never seen anything like it.

    Also, I was only looking at the meta arguments, I don’t know how the ‘posts’ or ‘wp_query’ arguments fit in, I have to assume they are proper, knowing nothing of View::render(). Are you sure they are proper?

    Is there a way to pass an array of post objects and get them rendered properly? I’m thinking do your own new WP_Query outside of View::render() and then pass the results to be rendered somehow. Or maybe it wouldn’t be too hard to write your own loop to output the same thing?

    I’m grasping at straws because I’m unfamiliar with your theme. As such, I’m not sure I’ll be of much more help ??

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Exclude meta_key from wp_query’ is closed to new replies.