Tag Info

Hot answers tagged

3

You can pass a space-delimited set of columns to orderby argument of WP Query: $args = array( 'meta_key' => 'wp_ratings', 'orderby' => 'meta_value_num date' ); $query = new WP_Query( $args ); You can also pass an array of key => sort_order for more granular control, for example: $args = array( 'meta_key' => 'wp_ratings', ...


2

Note that the relation part in the meta_query argument, is only used to define the relation between the sub meta queries. You can try this setup: $args = [ '_meta_or_title' => $thesearch, // Our new custom argument! 'meta_query' => [ [ 'key' => 'model_name', 'value' => $thesearch, ...


1

I figured it out: $the_query = new WP_Query(array( "numberposts" => -1, "post_type" => "plays_events", "meta_query" => array( array( "key" => "show_times_%_date", "value" => $this_month . "[0-9]{2}", "compare" => "REGEXP" ) ), ));


1

The way you did in your code you are querying posts with the key rw_related_link. If I understood you right, you must use get_post_meta inside the loop. <?php while ($normal_query->have_posts()) { $normal_query->the_post(); $related_link = get_post_meta(get_the_ID(), 'rw_related_link', true); // The value you want is ...


1

The arguments passed to the WP_Query class's constructor are used to describe the posts you are "looking for" in, and wish to retrieve from the database - the 'meta_query' argument is used to retrieve posts that contain a particular meta key and/or value. In order to actually manipulate (i.e. create/retrieve/update/delete) post meta-data, you should be ...


1

Add this code in functions.php. Use orderby with meta_value_num and define meta_key in argument array. add_action( 'pre_user_query', 'wps_pre_user_query' ); function wps_pre_user_query( &$query ) { global $wpdb; if ( isset( $query->query_vars['orderby'] ) && 'meta_value_num' == $query->query_vars['orderby'] ) ...


1

You are not going to this in one query, you will need to do two queries. The first query will hold the posts which will hold the meta key, the second will be the posts without the meta key. (Just a note: never use query_posts unless you intentionally wants to break things) You can try something like this $args1 = array( 'orderby' => 'meta_value', ...


1

You must use LIKE on the meta_key to support the SQL % pattern. The compare attribute only applies to the meta value. Instead you could try to filter it with: /** * Match any numbers in given a meta-key for WP_Query * * @see http://wordpress.stackexchange.com/a/177331/26350 */ ! is_admin() && add_filter( 'posts_where', function( $where ) { ...


1

As you can see in your custom WP_Query, you pass hardcoded aguments, you are not evaluating the arguments passed in the URL, so they does not affect to the result. In your case, it seems that using a custom query for the archive template is the bad way. When you request the archive template, the events for the archive have been already queried and you are ...



Only top voted, non community-wiki answers of a minimum length are eligible