Ah, I found the answer myself. I’ve added global $post before the loop and now all seems to works fine. I don’t know if this is a good practice, so if you have another ideas share them 🙂
Here is the revised code:
add_action('save_post', 'bulk_refresh');
function bulk_refresh($post_id) {
if($post_id != 123)//123 is the 'certain page' id
return;
global $post;
$posts_to_update = new WP_Query(array('post_type' => 'MY_CUSTOM_TYPE', 'posts_per_page' => -1));
while($posts_to_update ->have_posts()) : $posts_to_update ->the_post();
$args = array( 'ID' => $post->ID );
wp_update_post( $args );
endwhile;
// Reset Post Data
wp_reset_postdata();
}
Related Posts:
- Custom Blog Post Listing in Genesis Sample Child Theme
- providing access to post_id or post inside functions.php
- Hook for post and page load
- How to enqueue scripts on custom post add/edit pages?
- How do you use a CPT as the default home page?
- What is singular.php?
- Calling a Function After New Post Creation for a WordPress Custom Post Type?
- What are the differences between custom post type and custom page templates?
- Page Template as Custom Post Type Archive
- Setting a custom sub-path for blog without using pages?
- How to Debug the ‘save_post’ Action?
- Adding a drag and drop re-ordering from a custom post type default list [closed]
- Add Content to Page without shortcodes
- get_query_var() not working in pre_get_posts
- Unregister post type from child theme
- Filter for “get_post_type_archive_link()”
- How to add a button to custom post type’s posts-page
- Loading custom page template via plugin
- How to hook into the CPT’s title placeholder?
- Post formats “audio” and “video” only showing in index.php
- Ordering Posts List By Taxonomy Terms?
- Automatically fill custom field value on post publish/update
- flush_rewrite_rules on save_post Does Not Work on First Post Save
- Creating a Custom Post Type for Inserting Preset Content into Post & Pages?
- WordPress keeps fetching the archive page instead of the template page
- Why get_next_post_link() or get_previous_post_link() doesn’t return the required links?
- How to add custom template in plugin?
- Admin Post Update Redirection to Posts Screen
- How often do you need to register_post_type?
- How to quickly switch custom post type singular template?
- Add a Template to a custom post type
- How to use a dedicated template for the Custom Post Type from a plugin?
- How to create notification on frontend using heartbeat api for multiple custom post types
- WordPress calls archive page instead of Custom Page Template
- How to set a custom post type post as static front page?
- How do I Make a custom post type get a custom post template in a plugin
- With what hook can I address all posts from all custom post types when they are published?
- How to sort list of custom posts to get view like a tree of posts under categories and their children’s categories?
- Assign Page Template Within A Custom Post Type
- Dynamic page.php template for custom post types
- Custom post type archive and single.php files not working
- specify meta_key / meta_value condition for prev_post_link and next_post_link
- Page Templates – this code only works for one Custom Post Type
- Pagination on a custom page template
- Hook when adding or editing a specific custom post type? [closed]
- Custom Post Type – Archive page title
- WordPress custom post type Single.php?
- remove_action conditionally for Custom Post Type
- wp_update_post on specific custom post type
- Multiple templates for custom post type
- How do I create a custom post type for a training CMS in WordPress?
- What hook should be used to programmatically create a post only when master post is updated?
- Custom Post Types, Page Templates and Pagination. Why do I get a 404 Error?
- How do I create a page template to display a custom post type?
- Creating a function that receives the taxonomy terms that have been changed in a custom post type
- How to register custom post types in a plugin?
- How to make an archive page displaying posts in a date range
- Display Posts of a Category in Alphabetical Order (Custom Post Type)
- Add information above a custom post type listing of all posts page
- Custom Post Type slug same as page name causing a conflict
- Control Custom Post Type template from a plugin
- Detect if 1st, 2nd or 3rd level custom page?
- Remove “Get Shortlink” button in admin of custom post type
- Create second custom 404 page for selected post type
- is_page_template not working as expected
- Child page in custom post throws 404 page not found
- CPT: archive-cpt.php VS custom page template
- wp_update_post based function works on existing posts, but not new posts
- Multiple portfolios with one custom post type?
- Take Variables Set in Functions.php and Echo Them Inside My Custom Post Template
- Hyphens instead of Underscores in Post-type Archive Template Filenames when Post-type handle contains underscore
- Including Custom Post Type posts in a page template contextually (or should I widget?)
- Help with CPT template pagination
- Updating post title using wp_update_post
- After updating a page, all pages on the site used the index.php template
- Page Templates Drop Down Select for Custom Post Types
- Pull in custom content types into page template
- Editable content on a Custom Archive page
- Set a default category – if the user didn’t select one- before creating a post
- Using custom page templates with plugin [duplicate]
- Can’t unregister parent theme’s CPT from my child theme
- Modifying date filter on admin page for custom post type to link to custom field
- Can I make WordPress use a custom template for a child page
- How Can I Set the Post Author of a Post I Just Created With PHP?
- Troubles with making a custom template for posts
- Create Template for Custom Post Type same like for Page
- Hooking in to an archive page?
- Add custom column in custom post type edit page
- Creating a Page to View the List of Posts for a Custom Post Type?
- How to load a template without it being assigned to a page/post?
- Change archive page template using pre_get_post
- Custom template with CPT doesn’t display on frontend
- Insert Multiple Post with Same Publish Button
- Why is conditionally loading a custom plugin’s code only on a specific custom post type causing the site content to disappear?
- Validate custom fields before save using WordPress Rest API
- Custom Page that comes with preloaded content for the user
- How to: Display ACF [fields] on Custom Post Types Utilising WordPress ‘Hooks’? [closed]
- create a template page for a post
- Insert and then update post_type by wp_update_post
- Custom post type archive page template