In your template, the add_action
you have there is way too late because by the time WordPress gets to your template, the query has already been performed.
If this is for a category page, I’d do the following in your functions.php
:
//Display Gaming Trailers
function display_gaming_trailers( $query ) {
if ( $query->is_category() && $query->query_vars['category_name'] == 'video') {
$query->set( 'tag', 'gaming-trailers' );
}
}
add_action( 'pre_get_posts', 'display_gaming_trailers' );
Related Posts:
- Related Posts loop – offset
- Get titles of all posts with current tags except current post
- taxonomy tags 404 to custom post types
- A loop with all articles with certain text strings in tags
- How to show posts with multiple tags on tag.php?
- Problem getting current post tags to show in a widget
- How to show more random posts if Tag has less than 3 posts
- Exclude page name from loop
- how to replace get_template_part(‘loop’,’tag’) with explicit styled version?
- For each loop on every word in post
- Tags on page (not post) returns nothing – why? Improved clarified question!
- Include future posts in tags and in search
- how to run loop in function.php that sends email based on specific conditions?
- Using has_tag() outside loop
- Show posts by tags excluding current post
- WordPress Tags in class
- Secondary loop cuts off at 10 posts?
- How to show only specific tag in wordpress loop
- Tag custom loop show posts
- get_page() unlike Loop returns the post content without html tags. How can I fix this?
- How to do query_posts on tags pages
- Tags outside the loop
- Get date of last update outside of loop
- How do I get the attributes of a short code from a post?
- Show scheduled posts in archive page
- post__in – Placing content from a foreach loop inside of an array
- loop query exclude meta_key with meta_value
- “Blog pages show at most” in The Loop
- wp_insert_posts Fatal error: Maximum function nesting level of ‘100’ reached, aborting!
- Post Loop not Returning Permalink
- Custom page template
- Get posts that matches specific terms of multiple custom taxonomies
- add_filter() doesn’t work in loop
- The Loop in Static Page
- How can I use get_permalink() outside the loop?
- Content/Excerpt length control for a specific loop?
- How to check for specific content in comments in the loop
- Why we use if with while loop?
- Problem the_permalink
- Loop posts only excluding first post
- Loop repeating design pattern
- Create static front-page with 3-5 recent posts
- Customize WooCommerce Product Images (Placement and size) [closed]
- Create a loop that gets pages with their template
- Why is my loop not dynamically grabbing the correct Category and displaying all categorized posts?
- get latest 5 posts and a specific post and sort in a specific order
- How to check if a post exist?
- Query posts if meta key starts with
- 3 Posts in Loop, Show Stickies First
- Loop within a loop (Again) for template
- Why cant you place the Loop outside of the index.php?
- sticky post in custom loop
- Rating system and changing the loop
- Pagination for multiple loops
- Ajax Button to load more Posts into a timeline
- Infinite Scroll on a loop?
- On single.php, fetch 2 posts created after and 2 posts created before in relation to the actual post (using menu_order)
- Post classes in the loop are being changed in certain themes
- PHP if post is already displayed, then
- How to style first post differently with ‘get_template_part’?
- How can I improve the performance of this query_posts loop?
- Distribute Gallery Images Every nth in Loop
- WordPress Image Slider Looping Title Not Working
- Adding div after every two post on main loop! Why will first post not get counted?
- Second Loop Showing Only One Post on Single Post Page
- Pulling in featured image into default recent posts widget
- How to check if there are posts with the same tag
- how can i order the category by date
- Change position of entry title
- Print the whole page?
- excerpt not showing up
- Announces with different formatting dependently on a number
- Override orderby to create list of users by custom meta_value
- Loop info in jquery Tabs – loop into a variable?
- List page is showing 404
- Duplicated tag in loop
- Insert content above an embedded video inside Wordress’ php the_content
- Loop two different category WP_Query
- Use ACF Category Image for all Taxonomy Archive Views
- Loop with custom posts, to include information from different custom post type
- the loop printing post in one grid
- Check value of post meta within IF statement
- Transient not working for external data
- Get Sticky User in user loop based on user role
- the_title() Returns the page title instead of the post
- How do I aproach this?(for sale, for lease, sold->move something from a category to another)
- How to fix pagination for custom loops?
- query_posts ignores the argument
- Need some help with “the_widget()” function
- How to add excerpt in loop in Twenty Eleven theme?
- show posts from one category with comments only
- Loop from another WP site onto mine
- Having issue with WordPress loop
- Show only posts from todays date [duplicate]
- I need to update the post query? [closed]
- Wrap every 2 divs in row – for each loop [closed]
- How to add class to the last image of the last post in a loop
- Multiple loop with pagination in same page
- How to get files from loop for zip
- Query Loop Block: possible to restrict just child pages?