Sticky Posts & Posts Per Page [closed]
Sticky Posts & Posts Per Page [closed]
Sticky Posts & Posts Per Page [closed]
Yuo can also do it this way, count published posts, get settings posts per page, then divide. $published_posts = wp_count_posts()->publish; $posts_per_page = get_option(‘posts_per_page’); $page_number_max = ceil($published_posts / $posts_per_page);
You can add a posts_orderby filter to flip the meta_value: function wpse174075_posts_orderby( $orderby, $query ) { if ( $query->get( ‘orderby’ ) != ‘ddmmyy_date_format’ ) return $orderby; if ( ! ( $order = $query->get( ‘order’ ) ) ) $order=”DESC”; global $wpdb; $mv = $wpdb->postmeta . ‘.meta_value’; // Note SUBSTR() position (2nd) arg is 1-indexed. return ‘CONCAT(SUBSTR(‘ … Read more
An example that displays an admin notice listing a randomized array with all blog IDs, the result of a get_posts( array( ‘numberposts’ => 1 ) ) and marking the first one which get_posts result is different from zero. Result After refreshing: Code add_action( ‘admin_notices’, ‘wpse_60401_print_random_blog’ ); function wpse_60401_print_random_blog() { global $wpdb; $rows = $wpdb->get_results( $wpdb->prepare( … Read more
WordPress 4.0 allowed you to specify multiple orderby parameters and set the order of each independently. How to do it? Just make multiple refferences, here is one way to do that. $args = array( ‘orderby’ = > array( ‘title’ => ‘ASC’, ‘date’ => ‘DESC’, ) ); Learn more here… But only since WordPress 4.2 it … Read more
add : $inner_arrays[‘relation’] = ‘OR’; and then query will be like : $args = array( ‘post_type’ => ‘products’, ‘post_status’=> ‘publish’, ‘meta_query’ => $inner_arrays ); this works …. 🙂
You can accomplish this with multiple meta queries. $query->set( ‘meta_query’, [ ‘relation’ => ‘OR’, ‘wpcf-start-date’ => [ ‘key’ => ‘wpcf-start-date’, ‘compare’ => ‘EXISTS’, ], ‘no-start-date’ => [ ‘key’ => ‘wpcf-start-date’, ‘compare’ => ‘NOT EXISTS’ ], ] ); $query->set( ‘orderby’, ‘wpcf-start-date’ ); $query->set( ‘order’, ‘ASC’ ); This will tell WP to create a query that will … Read more
I would duplicate the coordinates of the posts in a separate table (post_id, lat, lon), with an index on (lat, lon). With all the joins and the casts I doubt the database can use an efficient index with your query. I once wrote an answer to a similar question using this approach.
Have you tried using get_posts() instead? //#get access to post settings global $post; //#set parameters for extra loop $args = array( ‘post_type’ => ‘mycustomtype’, ‘posts_per_page’ => 12, ‘orderby’ => ‘date’, ‘order’ => ‘DESC’, ‘post_status’ => ‘publish’ ); //#get posts $customPosts = get_posts($args); //#loop through them foreach($customPosts as $post) { //#set all the loop functions to … Read more
Did you try this? function sort_query($query) if ($query->is_tax() && $query->is_main_query()){ echo $query->query_vars[‘taxonomy’]; $query->set( ‘orderby’, ‘post_title’ ); $query->set( ‘order’, ‘ASC’ ); //do other stuff } } add_action(‘pre_get_posts’, ‘sort_query’); Happy Coding, Kuchenundkakao