WordPress.org

Ready to get started?Download WordPress

Forums

Events Manager
[resolved] Custom query ignores scope=future (12 posts)

  1. taras_bulba
    Member
    Posted 1 year ago #

    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/

  2. agelonwl
    Member
    Posted 1 year ago #

  3. taras_bulba
    Member
    Posted 1 year ago #

    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.

  4. agelonwl
    Member
    Posted 1 year ago #

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

  5. taras_bulba
    Member
    Posted 1 year ago #

    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?

  6. taras_bulba
    Member
    Posted 1 year ago #

    What I need to do is this:

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

    But using WP_Query

    Any help?

  7. taras_bulba
    Member
    Posted 1 year ago #

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

  8. agelonwl
    Member
    Posted 1 year ago #

  9. taras_bulba
    Member
    Posted 1 year ago #

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

  10. agelonwl
    Member
    Posted 1 year ago #

    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');
  11. munikho
    Member
    Posted 7 months ago #

    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 );
  12. Alessandro Muraro
    Member
    Posted 5 months ago #

    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'
    		)
    	)
    );

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.