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 do you use a CPT as the default home page?
- What are the differences between custom post type and custom page templates?
- Unregister post type from child theme
- Filter for “get_post_type_archive_link()”
- Loading custom page template via plugin
- Ordering Posts List By Taxonomy Terms?
- 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?
- How often do you need to register_post_type?
- How to quickly switch custom post type singular template?
- How to use a dedicated template for the Custom Post Type from a plugin?
- How to set a custom post type post as static front page?
- 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?
- Hook when adding or editing a specific custom post type? [closed]
- Custom Post Types, Page Templates and Pagination. Why do I get a 404 Error?
- Display Posts of a Category in Alphabetical Order (Custom Post Type)
- Add information above a custom post type listing of all posts page
- Create second custom 404 page for selected post type
- is_page_template not working as expected
- Multiple portfolios with one custom post type?
- Including Custom Post Type posts in a page template contextually (or should I widget?)
- Can’t unregister parent theme’s CPT from my child theme
- Creating a Page to View the List of Posts for a Custom Post Type?
- Why is conditionally loading a custom plugin’s code only on a specific custom post type causing the site content to disappear?
- Custom Page that comes with preloaded content for the user
- How to: Display ACF [fields] on Custom Post Types Utilising WordPress ‘Hooks’? [closed]
- Insert and then update post_type by wp_update_post
- Custom Post Type with Templates using Meta Boxes?
- Custom-Posttype & Custom Taxonomy WP_Query
- Page template with different page and post content
- Custom page sidebar using Template dropdown box
- Adding sidebar to template creates horizontal gap the size of the side bar
- Filter Posts from the Main Query
- Custom Post Type Template Alternative
- General advice on addressing content-centric pages
- next_/previous_post_link() `in_same_category` appears to fail when true
- Multiple templates for single custom post type
- WordPress Custom Search by post_type
- Pages Become “Archive” Instead of Using Page Template
- Categorise Custom Post Types
- Custom post type pages return 404 page?
- Add a custom text to admin footer in a Custom Post Type page
- Multiple single templates?
- Custom URL redirect in WP
- Programmatically change post visibility on save_post action return a 500
- page template for custom post type
- Page Template Dropdown For Custom Post Types
- sortable columns for multiple custom post types not working
- How to integrate single and archive templates for custom post type in any WordPress theme
- Why does wp_update_post causes white screen?
- How to build a WordPress post review system beside commenting
- WordPress hook after post content and meta update
- wp_get_canonical_url showing first url of the post for custom page
- Make a custom column sortable by a value from a different custom post type
- How can I modify a custom post type and custom page template for a child theme if all content seams to be handled by theme’s ‘native’ plugin?
- wordpress post_where set only for my costum post type
- Mixing Custom Post Types and Page Templates in WordPress 3.7.1
- Catch and display error on save_post action
- Loop and add Specific Categories and Products Images
- Custom Post Type page template doesn’t show up
- Problem with custom loop navigation inside the blog page
- WordPress giving me the index
- Can I automatically assign a page template to a custom post type (i.e page-slug.php file)
- Virtual page and loading template
- Custom Post type dont use custom page template (slug is not right)
- Best way to fix bad count on All | Mine | Published
- How to create additional rendering for custom post types?
- wp_set_object_terms creates taxonomies but does not add custom posts to it
- Custom Post Type action on post update
- Show Post Types customized in Template Page
- In child theme, add CPT to custom taxonomy registered in parent theme
- Update main post with same category when creating custom post to update the modified date
- Set a template on a custom post in the plugin
- How can I use a custom template to load custom post type posts based on a post_meta value
- Showing Custom Post Type with his templates on a custom page template
- Correct way to register custom post type from external php file?
- Question on templates
- How can I load Template file from wordpress plugin
- WordPress custom post type and page
- Execute code only after user clicks ‘update’ button for CPT being edited
- Ordering Posts List By Taxonomy Terms?
- Loading a template for a URL pattern
- Custom Post save causes 500 error
- Adding Information To All Posts Screen
- Custom Homepage As Single Page or Custom Post Type?
- Templates list in “Page Attributes” metabox is inaccurate
- Custom Post Type & Page Template
- Using custom post types within a section of a template
- How do I paginate a custom post type listing on a custom template page?
- Custom Post Type order Title ASC
- get tags from custom post type
- Custom Post Type Template Based on Page Slug?
- How to string lines from the_content() hook in WordPress?
- using a template for more then 1 page
- Change CPT Edit Target Link for Admin List