Using WP meta query to show custom post types by a start and finish date

The query will by default GROUP BY the post ID, meaning that a post will only appear once in the list. You can remove that GROUP BY pretty easily with a filter: add_filter(‘posts_groupby’,’__return_empty_string’); $events = new WP_Query($args); remove_filter(‘posts_groupby’,’__return_empty_string’); That might get you what you want. It is a bit hard to tell. Without the GROUP … Read more

Writing less unnecessary code with WordPress

Try this function cat_loop ($key){ $fashion_cat = array( ‘category_name’ => $key, ‘posts_per_page’ => 4, ‘post_type’ => ‘post’, ‘post_status’ => ‘publish’, ‘orderby’ => ‘date’, ‘order’ => ‘DESC’, ‘post__not_in’ => $already_posted, ‘category__not_in’ => $private_categories ); // Add the loop. } cat_loop (‘fashion’); cat_loop (‘beauty’); cat_loop (‘lifestyle’); put the loop in function which has variable for the category_name … Read more

Remove Post if Advanced Custom Field is checked to fix paging

Use WP_Query instead, and you can use the meta_key / meta_value parameters: <?php $paged = (get_query_var(‘paged’)) ? get_query_var(‘paged’) : 1; $args = array( ‘cat’ => 10, ‘paged’ => $paged, ‘posts_per_page’ => 12, ‘post_status’ => ‘any’, ‘order’ => ‘ASC’, ‘meta_key’ => ‘archived’, ‘meta_value’ => ‘true’ ); $posts = new WP_Query($args); ?> <?php while($posts->have_posts()): $posts->the_post(); ?> <?php … Read more

Category based on post id

WP_Query itself can’t do that logic internally but you can easily create the query dynamically. $args = array( ‘meta_key’ => ‘name’, ‘orderby’ => ‘meta_value’, ‘order’ => ‘ASC’, ‘posts_per_page’ => ‘-1’ ); if ($post->ID == 1) { $args[‘category_name’] = ‘first’; } elseif ($post->ID == 2) { $args[‘category_name’] = ‘second’; } $custom_loop = new WP_Query($args);

How to create Page templates for showing Blog posts in different layouts?

I wouldn’t use custom page templates merely for changing the layout of the blog posts index. Using page templates for the blog posts index bypasses the core handling for display of the blog posts index (which per the template hierarchy uses either home.php or index.php to render). Edit I never…said that I want to change … Read more

Current and next month posts

try this query_post for up to 3 posts for the current month: $current_year = date(‘Y’); $current_month = date(‘m’); $args = array( ‘year’ => $current_year, ‘monthnum’ => $current_month, ‘order’ => ‘DESC’, ‘posts_per_page’ => 3 ); query_posts( $args );