• Resolved taras_bulba

    (@taras_bulba)


    Hello,

    I’m trying to make a custom query to take the future events and display them in another custom plugin I’ve made. I’m using this query, but it will bring all the events, future and past, and ignore the scope. What’s wrong here? Thanks for your help.

    $query_args = array(
    
            'post_type' => $post_type,
    
            'posts_per_page' => $posts_per_page,
    
            'category_name' => $category_name,
    
            'tag' => $tag,
    
            'orderby' => $orderby,
    
            'order' => $order,
    
    	'scope' => 'future',
    
            'meta_key' => '_thumbnail_id' // Should pull only content with featured images
    
        );
    
        /* Allow the query args to be filtered */
    
        $query_args = apply_filters( 'arconix_flexslider_query_args', $query_args );
    
    	$fquery = new WP_Query( $query_args );

    http://wordpress.org/extend/plugins/events-manager/

Viewing 11 replies - 1 through 11 (of 11 total)
  • Thread Starter taras_bulba

    (@taras_bulba)

    I’ve read that thread and a couple more on the same issue, but I haven’t been able to figure out a solution by reading them.

    I think my problem is more simple that the one in that thread. I just want to query the events with scope=future, but the query comes with every event.

    What confuses me a lot is that this is not a complicated query, I don’t know if I am missing something too obvious here in my query.

    agelonwl

    (@angelonwl)

    sorry, I’m afraid that I can’t help you with custom codes.

    Thread Starter taras_bulba

    (@taras_bulba)

    Well, is not THAT custom, I just want to query the events with scope = future using WP_Query

    Is it that difficult or weird what I’m trying to do?

    Thread Starter taras_bulba

    (@taras_bulba)

    What I need to do is this:

    $EM_Events = EM_Events::get( array(‘scope’=>’future’) );

    But using WP_Query

    Any help?

    Thread Starter taras_bulba

    (@taras_bulba)

    Let me up this to see if I can get some help.

    agelonwl

    (@angelonwl)

    Thread Starter taras_bulba

    (@taras_bulba)

    No luck; still stuck trying to query the events with scope = future using WP_Query

    agelonwl

    (@angelonwl)

    maybe this snippet can give you some idea –

    function my_em_wp_query(){
    	$args = array(
    		'post_type' => 'event',
    		'posts_per_page' => 100,
    		'meta_query' => array( 'key' => '_start_ts', 'value' => current_time('timestamp'), 'compare' => '>=', 'type'=>'numeric' ),
    		'orderby' => 'meta_value_num',
    		'order' => 'ASC',
    		'meta_key' => '_start_ts',
    		'meta_value' => current_time('timestamp'),
    		'meta_value_num' => current_time('timestamp'),
    		'meta_compare' => '>='
    	);
    
    	// The Query
    	$query = new WP_Query( $args );
    
    	// The Loop
    	while($query->have_posts()):
    	$query->next_post();
    	$id = $query->post->ID;
    	echo '<li>';
    	echo get_the_title($id);
    	echo ' - '. get_post_meta($id, '_event_start_date', true);
    	echo '</li>';
    	endwhile;
    
    	// Reset Post Data
    	wp_reset_postdata();
    }
    add_shortcode('em_wp_query','my_em_wp_query');

    Tnx for the snippet @agelonwi, helped me on my way. Only thing is that a meta_query needs to have a double array apparently. Example from: http://codex.wordpress.org/Class_Reference/WP_Query

    $args = array(
    	'post_type' => 'product',
    	'meta_query' => array(
    		array(
    			'key' => 'color',
    			'value' => 'blue',
    			'compare' => 'NOT LIKE'
    		)
    	)
    );
    $query = new WP_Query( $args );

    So the resulting query arguments would be something like:

    $args = array(
    	'post_type' => 'event',
    	'posts_per_page'         => '4',
    	'meta_query' => array(
    		array(
    			'key' => '_start_ts',
    			'value' => current_time('timestamp'),
    			'compare' => '>=',
    			'type'=>'numeric'
    		)
    	)
    );
Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Custom query ignores scope=future’ is closed to new replies.