WordPress.org

Ready to get started?Download WordPress

Forums

Meta_query on custom post (3 posts)

  1. ebinion
    Member
    Posted 2 years ago #

    I am trying to use a custom query to retrieve set of events (custom post type) that are happening either today or in the future.

    I have a custom field that I'm using (stored as 'yyyymmddhhmm' for sorting but the meta_query doesn't seem to be working. Would anyone be able to tell me where I am going wrong?

    $query_args = array(
    	'post_type' => 'events',
    	'meta_key' => 'start_sort_timestamp',
    	'meta_query' => array(
    		array(
    			'meta_key' => 'start_sort_timestamp',
    			'meta_value' => 201203051100,
    			'compare' => '>=',
    			'type' => 'NUMERIC'
    		)
    	),
    	'orderby' => 'meta_value',
    	'order' => 'ASC'
    );
    
    $query = new WP_Query( $query_args );
  2. Gsiete
    Member
    Posted 2 years ago #

    I had problems ORDERing BY meta_values also and I found a post explaining that instead of 'orderby' => 'meta_value'
    'orderby' => 'meta_value_num' should be used

    Maybe this will also help
    http://wordpress.stackexchange.com/questions/20237/using-meta-query-how-can-i-filter-by-a-custom-field-and-order-by-another-one.

  3. ebinion
    Member
    Posted 2 years ago #

    Thanks Gsiete.

Topic Closed

This topic has been closed to new replies.

About this Topic