Possible to create a permalink to sort with meta_key?

What about something like that? function wpse139657_orderby(){ if( isset($_GET[‘orderby’]) ){ $order = $_GET[‘order’] or ‘DESC’; set_query_var(‘orderby’, ‘meta_value_num’); set_query_var(‘meta_key’, $_GET[‘orderby’]); set_query_var(‘order’, $order); } } add_filter(‘pre_get_posts’,’wpse139657_orderby’); In this way you can call your urls with a ?orderby=rank suffixed and it should do the trick. You can also have an optional order parameter, should you want to implement … Read more

Sort users by meta_value_num

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’] ) $query->query_orderby = str_replace( ‘user_login’, “$wpdb->usermeta.meta_value+0”, $query->query_orderby ); }

Display two post types ordered by two custom fields

My old code was wrong, this is a good one, as I think: function add_custom_post_type_to_query( $query ) { if ( $query->is_home() && $query->is_main_query() ) { $query->set( ‘post_type’, array( ‘post’, ‘facebook_events’, ‘event’ ) ); $query->set( ‘meta_query’, array( ‘relation’ => ‘OR’, array( ‘key’ => ‘event_start_date’, //this is from facebook_events post type ‘value’ => date_i18n(“Y-m-d”), ‘compare’ => ‘>=’, … Read more

Loop through two different sets of custom fields

Your question literally doesn’t quite sound like “combining” loops, that’s usually different thing in WP terminology. Following it literally you already know the part that outputs artist name you want — the_field(‘artist_name’). What probably confuses it in first context is that it’s not really a normal WP loop. Note how that call doesn’t specify which … Read more

Speed optimization of $wpdb->get_results

Your query is incorrect in the first place because you’re not doing the join correctly. What you’re actually selecting with that query is just all the postmeta’s autor fields, without regards to whether the post is published or not. Here’s the corrected query. SELECT meta_value AS autor FROM wp_posts JOIN wp_postmeta ON (wp_postmeta.post_id = wp_posts.ID) … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)