What you are doing is the safe way, and the way I’d recommend. To my knowledge, there is no Core function to bulk update only single values in the $wpdb->posts
table, so to do that you’d need to write your own SQL…
$ids = array(); // your IDs; I am assuming these to be validated and sanitized
$wpdb->query("UPDATE {$wpdb->posts} SET post_status="publish" WHERE ID IN (".implode(',',$ids)).")");
You might be able to do the same with $wpdb->update
but I rarely use that method, so I am not sure. (A comment below indicates that it is not possible.) Check the Codex and play with it if you want.
I would recommend not doing either, though, and continuing to use wp_update_post
. If you skip around the Core functions you also skip around numerous actions and filters, and may cause yourself unintended consequences or other frustrations later on.
Related Posts:
- How to add a button to custom post type’s posts-page
- wordpress remove views from action links in a custom post
- Add to ‘action’ within post.php to allow more actions when editing a Custom Post Type in a plugin
- Is it possible to get the specific content on the search page?
- Create a post automatically if search result has zero results
- Correct way adding External classes to Custom Post type and output their methods to template
- Widget area for individual posts (custom post type)?
- call a function when insert and update a custom post type
- How to change post cpt with submit button?
- I am having a problem with fetching product data in the Gutenberg block editor
- Post URL redirecting to homepage
- How Can I Set the Post Author of a Post I Just Created With PHP?
- Custom post type and body_class: Remove “blog” class
- WordPress Orderby Numeric Value Not Working
- Plugin translation not working apart from name and description
- Get rewrite slug of custom post type in template
- Exclude child pages from archive.php
- is there a way to retrieve posts that do not have a featured image assigned?
- Auto-generated posts not showing in backend (but being counted!)
- Custom Post Type rewrite
- Shortcode for display posts on home page show only one post
- Deleting Custom Post type data using mySQL command
- Admin notice not displaying
- How to Get Current Custom Post Type Selected Taxonomy Term (Not All Terms)
- Find the user who initially created the post
- Custom Post Type: Upload Multiple Images
- Need help targeting a custom post type with conditional tags
- How to get the post type from a category id?
- Detect where custom post type is declared
- Notice: Undefined index: suppress_filters
- Metadata for a taxonomy – is there any WordPress way of doing this?
- How to Separate CPT From Regular Posts?
- Remove rows in the manage post/page view
- Is there a way to have the view link on manage posts page to open in a new window or tab?
- How to create custom boxes with text inside?
- How to add post_type=value when editing that post type in the WordPress admin?
- Hook to override title, image and content
- 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?
- Adding dropdown select meta box to custom post type – seems restAPI is interfering
- Open Custom Post Type as PDF
- Using The REST API How To Pull All Custom Posts?
- How i can add ‘N’ page of ‘N’ pages under posts loop?
- get_object_taxonomies() returns empty array for custom post type
- WordPress theme custom capabilities not works
- custom post type not showing in menu
- Custom posts don’t work
- Show the same Article Available in Other Categories
- Getting posts under the custom post type ui category
- No posts found – Custom Post Type show_ui
- Storing posts from query and accessing later via AJAX call
- If post has custom field then display css-class
- How to customize a permalink (URL) structure?
- Adding a custom post type taxonomy template in plugin
- Plugin: register custom post types, child ready and performance best practices
- How to add a custom taxonomy to show up in a custom post type menu?
- Display only one post each WEEK
- List children on child post
- Restrict custom post type from appearing with ?post_types=
- Show custom post type filtered by category
- create parent post using wp_insert_post
- Turn on and off custom post type from admin?
- Missing Posts in Custom Taxonomy List
- Display random posts, but omit the post it is on?
- How do I do this with WordPress? Taxonomies?
- Give a permalink to Custom Post Types without title
- Disable block with taxonomies at post page
- I would like to have different styles for my posts based on the content of each post
- How can i add thumbnails images to particular post (using code not admin pannel) in wordpress
- Showing posts from different categories and from custom post type
- Get latest 3 posts from multiple CPT in one query
- Allow non-logged in users to see a future post after clicking on a list of future posts
- Which post does a taxonomy term belongs to?
- Getting template_include to work when allow_url_include is off?
- List custom taxonomy specific to one custom post type
- Post image in WordPress not appearing on home page
- How to add a custom-post-type post within another custom-post-type post edit screen using AJAX?
- Meta query for custom post type ignored in main query
- Changing custom type name hides the posts
- Display Ad on Specific Categories
- WordPress post_where & posts_join not working only for custom post type
- Add custom ID to CPT posts only create not update
- Hiding posts by other users and non-logged in
- Add custom post type as submenu [closed]
- WordPress multiple custom post types capability conflict in a single menu
- Update Post Meta for a logged in user
- Getting meta in editor plugin, and event triggering issue
- Add custom field to Posts and sort by it
- Orderby CPT custom fields not working
- Add custom post type settings to wordress default posts
- Unable to get Custom Plugin Options data
- Update post meta not working in transition_post_status
- Get related posts of child term of custom post type
- Two Custom Post Types Many to Many Relationship
- Problem with displaying posts in the CPT category
- Use custom metabox to update automatically a post after a given date
- JS innerhtml changing style when using AJAX
- Show titles, date of all posts on single category page
- Addition of custom option panel crashes Media Library & Admin Area
- Side effects of Script and Iframe in post