• kanika

    (@kanikawordpresscom)


    Hi,

    I donot know where this question belongs so kindly excuse me if it’s in the wrong forum!

    My problem:
    I am retrieving posts through the get_posts function as:

    <?php
    global $post;
    $args = array( 'numberposts' => 2, 'offset'=> 0, 'post_type' => 'webcast');
    $myposts = get_posts( $args );
    foreach( $myposts as $post ) :	setup_postdata($post);
    $p_ID = get_the_ID();
    ?>

    I want to say now that the meta_value parameter should be equal to either XYZ or ABC

    How do I do that?

Viewing 7 replies - 1 through 7 (of 7 total)
  • Thread Starter kanika

    (@kanikawordpresscom)

    It could help if the parameter could negated as in

    meta_value <anything but> ‘Live’

    Is it possible?

    Thanks,
    Kanika.

    Moderator keesiemeijer

    (@keesiemeijer)

    Try it with this [untested]:

    $args = array(
            'posts_per_page' => 2,
            'post_type' => 'webcast',
     	'meta_query' => array(
     		array(
     			'key' => 'yourmetakey',
     			'value' => array('XYZ', 'ABC'),
     		)
     	)
      );
     $myposts = get_posts( $args );

    Thread Starter kanika

    (@kanikawordpresscom)

    Thanks,

    That helped a lot! What worked for me was:

    //...code
                   'meta_query' => array(
                   'relation' => 'OR',
    		array(
    			//code
    		),
    		array(
    			//code
    		)
    )

    as given on the link u provided.

    I just have one more question. If I want to override the order_by according to the ‘meta_value’ parameter? As in, first we have all posts with meta_value ‘XYZ’ and then with ‘ABC’

    Thanks,
    Kanika.

    Thread Starter kanika

    (@kanikawordpresscom)

    Ordering by Date has temporarily solved the problem. (Per chance) But i’d still like to get an answer to this one.

    Thanks,
    Kanika.

    Moderator keesiemeijer

    (@keesiemeijer)

    As in, first we have all posts with meta_value ‘XYZ’ and then with ‘ABC’

    Try it with two loops (get_posts), one for ‘XYZ’ and one for ‘ABC’.

    Thread Starter kanika

    (@kanikawordpresscom)

    Oh, ok. Thought it could be clubbed into one.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘set multiple values for a single parameter in get_posts’ is closed to new replies.