Articles of wp query

Limit loop to future events

I have a custom post type, basic_events, with a custom date field, date_of_event. My view shows these posts in ascending order, based on this custom date field. $args = array( ‘post_type’ => array(‘basic_events’), ‘order’ => ‘ASC’, ‘orderby’ => ‘meta_value_num’, ‘meta_key’ => ‘date_of_event’, ‘paged’ => $paged ); Since everything is sorted by that field, and not […]

Adding a block with query in homepage

i want my 2 post blocks to show by Categories not recent And not by category. <!– Latest posts –> <div class=”home-section”> <div class=”container”> <div class=”row”> <div class=”col-md-12″> <div class=”section-title”> <h2> <?php echo _e( ‘گالری’, ” );?></h2> <span> <?php echo _e( ‘نمونه کارهای انجام شده’, ” );?></span> </div> </div> <div class=”grid-cover”> <?php $count=3; $args = […]

How to show list of posts with custom field value (a date) that are coming soon

I have a custom post type called client and it has a custom field of next_due_date, that is a date without time. I want to have a list of posts that have a next due date that is coming up soon. I tried creating a page template called “due soon” with this code (including changes […]

wp_query if have posts show date but not in loop

I have a wp_query set up to show events and I want to show the date if we have posts and if we do not I do not want to show the date. Here is my code: <?php $today = getdate(); $args = array( ‘post_type’ => ‘post’, ‘category__not_in’ => ‘-9’, // When live, will need […]

Query posts by views on category page

I’m having trouble trying to create a second query on the category.php pages, what I’m trying to achieve is displaying the most popular posts from the current category archive page being viewed. This is what I have so far. <?php // The Query global $wp_query; $term = $wp_query->queried_object; $args=array( ‘meta_key’ => ‘views’, ‘orderby’ => ‘meta_value_num’, […]

Function using get_posts() with tax_query not working when called from functions.php

I want to get an array of all the ‘bands’ in taxonomy ‘types’, and use the array later on in other functions etc. I have a utilities.php file that I require() in functions.php and it has the following function definition and a call to it right after: function get_all_bands() { $bands = get_posts(array( ‘post_type’ => […]

Custom navigation : show posts in sets of 4

I am trying to reproduce an existing site design in wordPress. The site has a sidebar navigation that shows 4 posts at a time, see here: I you click the “next” link in the secondary nav, you will see that the images in the side navigation stay consistent until the next set of four […]

More efficient way to list posts by category

This question already has an answer here: Get all categories and posts in those categories 6 answers

Finding the next 5 posts

On my single.php where I am calling my post I am wanting to run a query where I can catch the next 5 posts (chronologically). I know how to do everything except figure out a way to specify the 5 specific posts to be the posts created after my current post. using previous_post_link(); and next_post_link(); […]

How to access $wp_query object from array of posts given by get_posts?

I have a simple custom query driven by get_posts: <ul> <?php $args = array(‘post_type’ => ‘event’, ‘numberposts’ => 6 ); $myposts = get_posts( $args ); foreach( $myposts as $post ) : setup_postdata($post); echo ‘<li><a href=”‘ . get_permalink() . ‘”>’ . get_the_title() . ‘</a></li>’; endforeach; wp_reset_postdata(); ?> </ul> However, there’s a need to access this custom […]