How can I group posts by months and years?

You can do it like so: global $post; $posts = get_posts( array( ‘post_type’ => ‘press’, ‘nopaging’ => true, ‘orderby’ => ‘date’, ‘order’ => ‘DESC’, // it’s DESC; not DSC // There’s no use setting posts_per_page when nopaging is enabled. // Because posts_per_page will be ignored when nopaging is enabled. ) ); $_year_mon = ”; // … Read more

Merge two search functions for custom post type

Your functions are already simple enough, and secondly, the functions do different things: _s_staff_query() filters the posts query variables and the function has to run before WP_Query queries the database. _s_staff_search() filters the search results template and the function has to run after WP_Query queries the database. So just keep them independent.

Individual months in WP Query

It’s possible to pass multiple sets of arguments to date_query, so if you set relation to OR for them, you should get posts that match either, meaning that you could get the posts you want like this: ‘date_query’ => [ ‘relation’ => ‘OR’, [ ‘month’ => 1, ‘year’ => 2019, ], [ ‘month’ => 5, … Read more

wp_query get the 2nd post

I figured out you can use ‘offset’ => 1, to skip 1 post and get the 2nd. Change the number to however many posts you want to skip. ie. set it to 2 to get the 3rd. $loop = new WP_Query( [ ‘post_type’ => ‘product’, ‘posts_per_page’ => 1, ‘offset’ => 1, ‘meta_key’ => ‘total_sales’, ‘orderby’ … Read more

400 Bad Request, in wordpress theme development, wp_ajax

The problem is that, you have added extra white space before wp_ajax action. remove space from actions ‘ wp_ajax_my_action’ and ‘ wp_ajax_nopriv_my_action’. because of extra space before ajax request, showing the 400 bad request error. You should use : add_action(‘wp_ajax_my_action’, ‘my_action’); add_action(‘wp_ajax_nopriv_my_action’, ‘my_action’);