From pre_get_posts
in Codex:
Identifying Target Queries
When using pre_get_posts, be aware of the query you are changing. One useful function is is_main_query(), which can help you ensure that the query you are modifying is only the main query. Use it in combination with other conditional tags to only alter the main query on the pages you want.
pre_get_posts
is executed for every query on a page, which includes the query that loads your menu items, so you need to check if $query->is_main_query()
before you modify it, otherwise you’ll apply your query modifications to other queries.
Related Posts:
- Get main parent category for post (WordPress/Advanced Custom Fields)
- get_category only returning details for ‘uncategorized’
- Display all values of custom a field created with ACF on a page
- What does the token %1$s in WordPress represent [closed]
- exclude multiple terms using get_terms() function
- If Custom Field is empty don’t display div
- Archive listing of posts by publish year (multiple years)
- Add custom field to attachments in a specific category
- Display all posts in current category
- The values of custom fields are not available functions.php
- How to display related posts from parent category
- How can I set custom order use this function
- Put a link to a category round a hard coded A HREF
- Check if Product is in a Specific Category in Functions.php
- ACF: Only get first row of a Repeater Field
- Category Thumbnail Display – How to display ONLY the main Category
- Creating a related post section based on similar categories
- Swapping wp_dropdown_categories function with wp_category_checklist
- Using Advanced Custom Fields to create a per page slider
- Display PHP within HTML values
- Issue adding sub category programmatically
- Grab posts by multiple categories
- Unable to write multiple values back to ACF user field – PHP
- Update grandchild repeater field with value per row
- how to save selected option in variable for rest api category filter
- Recent Posts Not Showing Only On A Specific Category Page [closed]
- Display category name only once inside loop
- Sort by page information by Ascending Numbers
- how to show only specific category for a template
- Creating sub-categories via php
- Edit the_category (); for a hierarchical display
- Download PDF after CF7 form submission
- Displaying posts based on category
- How do I remove a category from a wordpress loop>
- Get categories names as an array to use it in theme settings
- Upload non-featured image to image field
- How to get the last category name of a child category?
- HTML Special Characters in URL string [closed]
- InnerBlocks with allowedBlocks not working with acf_register_block
- Accessing values from ACF sub field (flexible content area) in PHP
- Creating an image from a custom field
- ACF & Bootstrap Gallery Shows Blank Slides [closed]
- How to separate categories with commas?
- Show all tags within a category?
- Getting taxonomy category Image from ACF [closed]
- Alphabetically Ordered Category in WordPress
- Loading Posts & Category with Ajax
- How to get current category
- WooCommerce: Display product categories to make IF statement
- Trying To Get Child Categories To Show, Issue With foreach Loop
- Show parent categories of the current category
- How to check if a category has a parent and child categories?
- Get category id when SEO URL is turned on
- Display latest post from WordPress Featured Category that is also in X,Y,or Z categories
- Display Post Title From Select Choice Loop in Advanced Custom Fields (ACF) – WordPress
- Display Sibling WooCommerce Product Categories on Archive Page
- Add class to all img if they have a certain ACF field
- display the months of a specific category
- Custom front-end form for adding post – Category problem
- Add a product category to a specific product via a button
- List sub categories and corresponding posts of a parent category
- Dropdown category field inside repeatable metabox
- Bootstrap 4 Carosuel with ACF Repeater field
- How to display acf field values from home page on all pages?
- Set ACF on order during checkout
- How to Link to category titles if it is in the single post content?
- Get field value and use as variable in php
- How can i show specific Category List?
- How to show category just on specific pages?
- get_template_part() not working with Advanced Custom Fields plugin
- List all ACF field values across every post on one page
- How to filter specific element of an array in wordpress/php?
- PHP/CSS: Shortcode won’t display correctly, and only displays in the head (before content)
- How can I copy an ACF field to AIOSEO field? [closed]
- Make sticky post with FacetWP
- All categories options or All categories not Populating
- PHP for loop not working as intended
- List categories assigned to a post
- Unable to get Post Category Name and URL
- Else if Statement for Advanced Custom Fields [closed]
- How to add style in functions.php depending on conditions?
- How do I display Category titles on a WP Page?
- problem with category menu, it doesn’t want to show link
- Saving category as insert post
- ACF loop and php formatting
- Trying to see if page is category or single and displaying title with appropriate heading tag
- !in_array doesnt recognize category
- Custom field within shortcode
- How to change links in the 3 main categories, on widget category, to a javascript function call
- how to set category name for a post
- category & sub category order issues in wordpress
- ACF allow zero as a value
- Advanced custom fields Repeater conditional statement not working [closed]
- Fix incorrect related posts code snippet
- Display a list of posts corresponding to a category
- How to create categories out of a list of words?
- Is there a way of displaying related posts from lowest hyrachical order (lowest child category to parent category)
- Hide child of parent categories already hidden with “get_terms_args” – Woocommerce
- Exclude a category ID from the following function
- ACF number less than comparison not working