The post’s data is passed as an argument to the function hooked to transition_post_status
, so you don’t need to query for anything (also, your query is a bit strange, using both WP_Query and query_posts, but that’s a separate matter). Here’s a trimmed version of your function showing the important changes:
function a_new_post( $new_status, $old_status, $post ){
if ( 'publish' !== $new_status or 'publish' === $old_status )
return;
$posttags = get_the_terms( $post->ID, 'post_tag' );
if( $posttags ) {
$blogusers = get_users();
foreach( $posttags as $tag ) {
// the rest of your code
}
}
}
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
- Display Posts Only with Specific Tag
- 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
- 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
- Changing behavior of the loop twice in one page
- Displaying child page content of a certain parent
- Pagination adding extra posts only on page 2
- If Loop has odd number of posts on last page Custom style for last post in it
- Custom page template
- Get posts that matches specific terms of multiple custom taxonomies
- The Loop in Static Page
- How can I use get_permalink() outside the loop?
- Category archive page – loop through posts of certain tag (with pagination) – pre_get_posts
- Two loops by pre_get_post on same page
- How to check for specific content in comments in the loop
- Problem the_permalink
- Sort Posts By Category?
- Can’t access login screen, wp-login.php 404’s
- Create static front-page with 3-5 recent posts
- Customize WooCommerce Product Images (Placement and size) [closed]
- get latest 5 posts and a specific post and sort in a specific order
- How to check if a post exist?
- How to use current_post to open a new unordered list every five posts
- Why cant you place the Loop outside of the index.php?
- Pagination for multiple loops
- 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’?
- “Call to a member function have_posts() on array” error on have_posts();
- How to exclude or filter password protected posts when using next_post_link() previous_post_link
- How to append a query string to pagination?
- Get the image src and href data from posts
- Sending mail not working correctly
- WordPress shortcode in content, output in sidebar?
- Using variable in WordPress loop as criteria
- Call wp-blog-header.php header without performing a wp_query
- Display post formats differently on index.php (loop in function)
- Get_template_part() problem with the_content()
- How to output thumbnail twice in a loop
- Frontpage pagination by week
- Integrating WordPress with Your Website
- Multiple instances of Featured Image Thumbnail As A Background On Homepage
- Altering “posts_per_page” for defaut loop
- Why doesn’t ‘continue’ work in page?
- Display more than 10 posts on author.php file
- Accessing the Posts page Content
- Pagination for two loops
- Announces with different formatting dependently on a number
- Override orderby to create list of users by custom meta_value
- Thumbnail Image Rounded Corners w CSS (or any other good method)
- Several loops in sidebar issues
- List page is showing 404
- Duplicated tag in loop
- Loop only shows first two posts
- Why is my archive page looping through all but one post?
- 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
- tag based subscription
- My WordPress installation doesn’t load correct template
- Transient not working for external data
- adding tax_query to $query_string
- Remove posts_orderby filter then add it back in
- the_title() Returns the page title instead of the post
- WP update_post_meta link loop
- How do I aproach this?(for sale, for lease, sold->move something from a category to another)
- How to fix pagination for custom loops?
- Conditional Check in The Loop’s Parameters
- How does the JSON API work to parse incoming JSON and fetch a post based on an ID?
- How to add excerpt in loop in Twenty Eleven theme?
- show posts from one category with comments only
- How to implement template file and the loop
- Show only posts from todays date [duplicate]
- I need to update the post query? [closed]
- Multiple loop with pagination in same page
- Why did my most recent article fall behind an older one on my site?
- How to get files from loop for zip
- Divide loop into several columns based on post custom field and enable infinite scrolling
- Query Loop Block: possible to restrict just child pages?