'the_posts'
is an action fired everytime WP_Query
get posts, for main query and for other secondary queries, so when you do something like:
$foo = new WP_Query($args);
in a widget or elsewhere (shortcode, related posts…) 'the_posts'
is triggered again.
However there is only one main query, so you can use a conditional and do what you do only if the query that trigger the action is the main.
Luckily 'the_posts'
pass to hooked functions the query object so you can check if is the main using WP_Query::is_main_query()
method:
add_action('the_posts', 'check_my_endpoint', 10, 2);
function check_my_endpoint( $posts, $wp_query ) {
if ( $wp_query->is_main_query() ) {
global $wpdb, $cardcomm; // no need to globalize $wp_query, we have a reference to it
if( isset( $wp_query->query_vars[cardcomendpoint]) ) { ... }
}
}
Related Posts:
- How to publish a post with empty title and empty content?
- How to add a “publish” link to the quick actions
- how “manage_posts_custom_column” action hook relate to “manage_${post_type}_columns” filter hook?
- How can i do something after head like adding a hook for after head but before post
- How to generate numbers indistinguishable for the IDs of the posts
- Prevent posts with certain post_meta to be edited
- Exists filter or action that change Add New Post link?
- the wp_post_update isn’t working all the time
- Is it possible to completely replace a post with an action/filter?
- Is there a action hook for the “Empty Trash” button?
- How to validate XML-RPC post creation and cancel when needed?
- Removing filter dropdown in posts table (in this case Yoast SEO)
- Get old values for post before saving new ones
- Create posts on user registration
- How does filter the_posts work?
- Action hook ‘wp’ firing twice… why?
- Why is wordpress removing some unicode characters (e.g. some emojis) when I save my post?
- Count singular post views automatically
- Exclude category on blog list page
- How to remove_filter that filters iframes in posts? [duplicate]
- Filter post before *editing*
- Get the post_id of a new post
- Custom function for “Submit for Review” hook
- How to filter content post only on save
- If specific user role then sticky post
- add_action not using ‘delete_post’ action with wp_delete_post
- Getting post id from wp_insert_post_data function?
- Filter Posts By Tag
- Custom excerpt length filter doesn’t work
- Only display posts after current date
- Amend wordpress password function
- Custom Post Templates
- How to filter posts that belong to a specific category only if that is the only category
- How to retrieve the postID in a “image_send_to_editor” hook function?
- Filter Custom Post Type by Category with Ajax
- Ajax posts filter by date, comments, top views, top likes
- How to add Tags Filter in wordpress admin dashboard
- pre_get_posts query between 2 dates (date stored in custom post meta)
- how to remove dash (-) post status from post title on posts listing page wordpress
- Get latest posts from WordPress site without header, menu and sidebar
- Modify Image Source With The_Content Filter?
- Change post order random through out the entire WordPress
- use wpml_post_language_details function other plugin based on $post->ID [closed]
- How to hide html tags on revision comparison pages?
- Add filter by custom field to block of posts
- Ajax post filters not working
- Default to ‘all’ view on the ‘edit-post’ screen for authors
- More then one menu items are assigned with “current-menu-item” class
- How to access $post from a callback function
- Set static page/post from another blog on same network
- How to allow visitors to filter posts by multiple taxonomies
- Copy post to separate database with “add_action(….)”
- Call Web Services on post first publish
- Create new custom post and post category of same name
- add to end of post in the loop with plugin
- What does WordPress do if I save a post without content/title? [duplicate]
- Adding bootstrap classes to video shortcodes
- Is it possible to filter the main loop to exclude posts from a specific category?
- Divs appearing everywhere in post content
- Modify posts listing at back end
- Hook for changing excerpt content when excerpt not set
- Update post meta within save_post action
- How include css class based on post ( in loop ) slug?
- Restrict displaying posts to the poster itself (in Back-end)
- changing parent_id on post
- Actions to use when flushing cache (when posts are added / deleted / modified)
- Trying to exclude custom posts based on date, while sorting by custom field
- can’t modify post title using the_posts filter
- Show only posts with titles/permalinks that do not contain certain words
- user_has_cap filter allows “edit_others_posts” but not is not allowing updating/publishing
- Using AJAX to filter posts without refreshing page
- Is there a way to know when a page has been updated and do some action only once?
- Filter posts by month (dropdown)
- Display/Filter post using if else statement
- Count singular post views automatically
- Dropdown Select Post Filter
- How to add a block to a category page?
- Add view to admin menu to filter for specific criteria ( If post is child of specific Parent )
- show only one category and filter by tag
- Prevent WordPress from putting around specific element
- filter buddypress users posts by user ‘xprofile’ custom fields
- Override wp_link_pages pagebreak with filter
- How do I change the post title’s link on the posts page?
- How can i take all ids from untrash_post action?
- Grab meta data before post is saved
- How to create frontend Post filter using meta query
- Printable Page with all Posts from Tag
- How to test if user is filtering post list in dashboard
- Hide Admin posts & pages in Dashboard
- Extracting a TLD from the content and assign to custom field
- How to get the postID inside ‘content_save_pre’? Other hook?
- Filter question list on substring of metavalue
- Hook To Get All Posts Deleted
- Get results from the main wp_query
- Keep post format class with isotope filter
- Custom filter on all post page (admin backend)
- How to use in_category?
- the_content() not displaying the full post
- Action while post is being published
- Add custom PHP (no-SQL) filter to WP_query