When the instance of WP_Query is not a variable on the PHP file you are working on it tends to be the “main” query and to edit this instance of the WP_Query you will need to Hook to the pre_get_posts
action and change what you need there. Here is an Exemple:
<?php
add_action( 'pre_get_posts', 'q166401_pre_get_posts', 10, 1 );
/**
* On this case I will filter only the Home and the main query
* @param WP_Query $query The query object
*/
function q166401_pre_query( $query ){
// Stop this function when it's not Home or it's not the main query
if ( ! $query->is_home() || ! $query->is_main_query() ) {
return;
}
// Here you will set the filters you want
$query->set( 'order', 'ASC' );
}
If you have any problems referrer to the codex page related to this hook.
Related Posts:
- Counting the posts of a custom WordPress loop (WP_Query)?
- Get post content from outside the loop
- Is there any difference between the_title() and echo get_the_title()?
- Using the Loop to show all levels of subpages under a parent page? Halfway there
- Cleanest Way to Select Every Second Element in a Loop?
- Pagination not working on home page
- How to Change Loop to Order Posts by Views (using wp-postviews plugin)
- Get ID of a page containing secondary loop in content
- is_home, and is_front_page conditional problem
- Is `query_posts` really slower than secondary query?
- Are there any scenarios where the query_posts may be used?
- Display subpages under parent page as a list within a loop
- When to use wp_reset_postdata();
- Why do themes have `while( have_posts() )` in templates like single.php?
- Exclude category by slug for for each loop
- Related Posts loop – offset
- Too many nested wp_query loops in this hypothetical query?
- pop-up lighbox with AJAX
- WordPress Loop Through Particular Pages
- Showing current subcategory
- Display date only once for a each set of posts relating to that date
- The main Loop is not starting in a custom blog template page
- WordPress Loop – Style rows of posts differently
- Generating dynamic Tabs with multiple query post loop
- How do I override part of the main loop in my child theme?
- Chopping up a large ajax request of around 200 posts [closed]
- Combining the_excerpt with the_content
- Custom loop with conditional statement to separate each terms
- Breaking the loop?
- How to get an array of years from all of the search results, and use it to filter by year the paginated loop?
- Only display videos and images in the_content() within loop
- woocommerce stored variable
- Get search.php results in header.php?
- Recent posts on a static home page
- Query last updated posts (posts updated in the last 24 hours)
- I write simple wordpress loop for taxonomy.php file but don’t show result
- Publish Categories for a particular Author on a given Post
- Do I need to use The Loop on pages?
- How to hook into container
- Is wp_reset_postdata() redundant after the main loop?
- Exclude first post (sticky or not) from the loop using query_posts()
- How to add a specific div element to the first post in a row?
- While loop with bootstrap [closed]
- Need to add class to first element in a foreach loop
- Scrolling Posts with Ajax
- Sort posts by first letter in the title, not by first number
- how to replace get_template_part(‘loop’,’tag’) with explicit styled version?
- What PHP Needed to Make One Loop with Multiple Styling?
- Simple foreach loop help needed in wordpress “the loop”
- Get paged outside of loop?
- Show scheduled posts in loop (but don’t link to them)?
- How to get a count of all posts in foreach loop and split into fourths
- Grabbed Post ID under WP loop, but still couldn’t Print Post title
- How to loop through yoast primary categories? [closed]
- How to separate posts loop in to two columns? [duplicate]
- WordPress get post thumbnail url
- How can have a conditional template tag based on the main loop within a secondary loop with new WP_Query(), using get_template_part()
- How to render the single post template with the post name?
- WP_Query is only looping home page, not pages
- How to filter posts by category INSIDE the loop
- static page with multiple loops breaks post pagination
- new custom theme – posts displaying on top of one another
- Help with if and else statement
- Building a form with WordPress, and also pulling that data for a user page
- Custom Header added within Dashboard pages, is this possible with custom template files?
- Loop order issue with Ajax filter
- Adding a second loop breaks everything
- Custom Query with Sticky Posts
- is it bad to copy the loop for a template?
- I want to load post in bootstrap Modal dynamically
- Why my loop is repeat?
- Excerpts not showing on main page
- dispaly all hierarchical post types from a taxonomy
- Return only one post format in index.php [duplicate]
- How to display just video post format?
- Is it possible to get a post ID of a 2 different custom post types loop embedded in the same post to perform update_post_meta from the frontend?
- Loop shows post 5 times in a query
- How to execute custom loop before loop content?
- Make custom WordPress comments list
- Template included with plugin doesn’t return all posts for custom taxonomy
- Sorting posts to make those with post thumbnail show up first
- Best way to check if a post with specific meta exists
- Limit article to 100 characters. Can’t use the_excerpt…
- Return only content in excerpt field in loop
- Default Template infinite loop of Title
- Adding pagination to WP_Query [duplicate]
- This webpage has a redirect loop issue with SSL page
- Buddypress Group Activity Loop Filter activity type [closed]
- get_posts and wp_autop (remove filter)
- Trouble preventing duplicate posts between 2 loops on homepage
- Change the way wordpress outputs images or image galleries
- How can I access ‘key’ and ‘value’ from an array in a for loop?
- How to get current page id and compare it to looped pages inside the same page?
- Show amount of posts created today above loop?
- posts_nav_link() not working on index.php
- $do_not_duplicate is not working in genesis theme
- Loop displays current page
- Error in Wordprewss loop for page template [closed]
- Tags outside the loop
- Hook in the loop after the first post