The function the_post()
(source) triggers the action loop_start
when it is first used in the loop. This is used in every WP_Query
loop, so you may want to check if the current query is the ‘main’ one (assuming that’s the query you wish to target)
add_action( 'loop_start', 'wpse107113_loop_start' );
function wpse107113_loop_start( $query ){
if( $query->is_main_query() ){
}
}
The last time have_posts()
is called it triggers the action loop_end
(source), so similar to above:
add_action( 'loop_end', 'wpse107113_loop_end' );
function wpse107113_loop_end( $query ){
if( $query->is_main_query() ){
}
}
Related Posts:
- Manually set global $post vars with an ID, in order to use template tags
- Is it possible to define a template for a custom post type within a plugin independent of the active theme?
- Ways to have multiple front-page.php templates that can be swapped out?
- Define Function in functions.php or plugin and call in theme loop
- How can I let users to access plugin functions based on roles?
- Template for custom post type shows all posts instead of just one
- Fastest way to loop through all posts?
- How does WordPress ensure plugins run at the same time and how does it solve a plugin’s dependency on another one?
- post expire after x days
- Can’t get custom posts of taxonomy to show
- Display content from custom post type if match to main post category
- how do i remove posts from a WP_Query so the pagination is right?
- Override global query results without hooks
- Use wordpress functions in another PHP file
- Fetch Children of Grouped Products Inside WooCommerce Product Loop
- Insert content of a post into another
- Problem with the Loop – want to limit the access to three free articles
- WordPress Plugin manipulate have_posts()
- Get User_id outside wordpress,
- Calling the_excerpt from inside a plugin template file
- Recent posts per category loop?
- Import Instagram post to WordPress blog post
- Bulk update wordpress posts
- How to get a list of bundled products using wp_query in woocommerce
- Where to find the code used to render a page that has a shortcode and a template defined?
- Loop in elementor custom widget not working
- get_users(); Is an Undefined Function When Used in Cron Job
- Trying to add_action in a loop
- Loop returns the current page’s permalink and guid instead of the post in the loop
- Get post content from outside the loop with plugin shortcode usability
- Price comparison table based on Custom Post Type?
- Show related posts based of current ACF field name in a single page post (a loop within loop)
- Remember the Meta Value With Radio Buttons
- Output after specific post in the loop
- Plugin is creating posts twice
- Polldaddy doesn’t show up on own theme
- Add custom PHP and HTML to the_content()
- Multiple images per post – Show random image elsewhere
- How to modify the Loop from a plugin (instead of a theme)
- i need to make custom cron_schedule with custom interval time as a parameter into a custom payment gateway plugin wordpress
- Can’t add new plugin or themes on a wordpress multisite network from the primary site as administrator. Error: ERR_TOO_MANY_REDIRECTS
- Create post loop that displays pages by cat ID
- Place content inside the Post Loop
- Cannot reset a loop in a plugin template
- Displaying image from a repeatable group
- Multiselect value in wp_query
- Advanced Custom Fields (ACF) Plugin – Random Image in Sidebar
- ‘all’ hook and add_action issue (class based plugin)
- Fake Single WordPress Post (Page) Loop
- single.php fires more than once after clicking on any post to view with different post id each time
- How do i use postMash to order posts in a custom loop?
- How can I save a setting field with multiple checkbox options generated by a foreach loop on a custom wordpress admin page?
- Getting Post Permalink Outside of Loop Not Working
- Trying to display posts but getting the pages as output
- How to dispaly post informations (such as titles) in an admin plugin menu page?
- Outputting custom field query from a plugin to the website header
- How to display content depending on the Woocommerce Product Category
- Page with redirect
- FacetWP custom display based on post type [closed]
- Creating a plugin with dependencies
- difference between add_options and register_setting
- Creating a WordPress admin page without a menu for a plugin
- How can I mass-update/save all WordPress posts and pages?
- Create plugin with 3rd party MIT license code
- Notice: wp_get_http is deprecated since version 4.4.0!
- How to check plugins for malicious code?
- How to add usermeta to “Notice of Email Change” email message
- How to create a Page alias in WordPress
- Remove from Google Tags with less than 2 posts
- Adding dynamic section to WordPress
- Add Fields with Sub-Fields to WP Job Manager
- Disable wp_enqueue_styles action for specific page
- Getting RGBA colour from gutenberg colourpicker
- Facebook plugin shows existing comments
- How to trigger $_GET request within admin plugin page?
- How to configure two SMTP Server for wordpress
- Using a post-signup hook to get user details
- How to merge two .PO language files?
- AFNetworking incorrectly interpreted WP_Error
- How to create multiple database tables on plugin activation?
- Is it possible to remove subscription box from Jetpack stats page? [closed]
- How to display terms and conditions in post area?
- Moving FB comments at the end of page
- How to override the Buddypress bp-members folder’s file?
- Use Plugin Whenever One Exists?
- Get data from wp_posts of mysql in to variables of wordpress-php script
- Change url of posts with keywords
- WordPress plugin won’t create custom tables
- Display Author name PHP (Selfmade Plug-IN)
- wordpress plugin add page when activate
- Validating ajax search
- Plugin Version List not Shown
- Scheduled emails to include only posts and calendar events for the upcoming week
- How to change meta data(title, description) for current post?
- To Store value in variable via text box
- How to make plugin work in each template in wordpress
- Expanding / Collapsing Modules in WordPress Panel
- Strange Search Query Appearing on Google Index – “/?q=Save+Us+From+Berlusconi”
- How put a file when the email is sent to user contact form 7
- Create Custom Coupon Type