Query Posts that have or don’t have a meta_value and order by the same ASC

You can do this by naming index of meta query, then passing array of these names in orderby parameter $args = array( ‘post_type’ => ‘post’, ‘post_status’ => ‘publish’, ‘posts_per_page’ => ’10’, ‘meta_query’ => array( ‘relation’ => ‘OR’, ‘with_time’ => array( ‘key’ => ‘TIME_meta_key’, ‘compare’ => ‘EXISTS’ ), ‘without_time’ => array( ‘key’ => ‘TIME_meta_key’, ‘compare’ => … Read more

Best way to sort posts with different types by distance

OK, I added distance as custom field to allow me order them using wp_query orderby method! function add_distance_as_customfield($posts){ $longDest = $_GET[‘lng’]; $latDest = $_GET[‘ltd’]; foreach ($posts as $post) { $placeLocation= get_field(‘location’,$post->ID); $longPlace =$placeLocation[‘lng’]; $latPlace = $placeLocation[‘lat’]; $distance=getDistance($latDest,$longDest,$latPlace,$longPlace); if ( ! add_post_meta($post->ID, “distance”, $distance,true ) ) { update_post_meta( $post->ID, “distance”, $distance ); } } }

Create custom order sortby based on array of id

It looks like you want to order by post__in: $samp = array ( ‘post_type’ => ‘product’, ‘posts_per_page’ => 12, ‘post__in’ => $init_ids_arr, ‘orderby’ => ‘post__in’, // <– Try this to fix the order ); We might also want to skip the sticky posts with: ‘ignore_sticky_posts’ => true, If we want to display all of the … Read more

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