Skip to:
Content
Pages
Categories
Search
Top
Bottom

get events


  • nicow65
    Participant

    @nicow65

    Hi i’m working with buddyppress and events manager. All I want to do is very simple but it’s not working.

    I’m using this piece of code :

    $args = array(
    ‘post_type’ => ‘event’,
    ‘posts_per_page’ => ‘-1’,
    ‘meta_query’ => array(
    array(
    ‘meta_key’ => ‘group_id’,
    ‘meta_value’ => ‘1’,
    )
    )
    );
    $myPost = get_posts( $args );

    As you can see I want to retrieve the events post type who belongs to the group with the ID 1. But it’s not working. I tried switch to ‘1’ , 1, ‘_group_id’ to ‘group_id’ but still not working, this script retrieve me every events.

    Can someone help me ? thx

Viewing 1 replies (of 1 total)

  • Henry Wright
    Moderator

    @henrywright

    Try this:

    $args = array(
        'meta_key'       => 'group_id',
        'meta_value'     => '1',
        'meta_compare'   => '=',
        'post_type'      => 'event',
        'posts_per_page' => -1
    );
    $query = new WP_Query( $args );
    
    if ( $query->have_posts() ) {
        // Events
    } else {
        // No events
    }
Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.
Skip to toolbar