The function you are looking for is wp_update_post()
.
You would want to have your posts which you want to update, then set up a loop to update each one individually.
// However you get your posts, ID's, etc.
$posts = get_posts( array( 'post_type' => 'post' ) );
for ( $posts as $post ) {
wp_update_post( array( 'ID' => $post->ID, 'post_parent' => 8 ) );
}
For a generic SQL call, look at the $wpdb
object, and it’s prepare
and query
functions:
global $wpdb;
$query = $wpdb->prepare( 'UPDATE wp_posts SET post_parent = %d WHERE post_type = %s', 8, 'my-post-type' );
$wpdb->query( $query );
You could also look into $wpdb->update
– it may suit your needs better in the future.
Related Posts:
- wpdb custom post_type problem
- $wpdb: Counting posts corresponding to 3 terms in 3 different taxonomies
- Insert post metadata for all posts in CPT at once if metadata no existent
- $wpdb is queried but results don’t show
- Create a WordPress Database query to find users who purchased specific product through WooCommerce [closed]
- Get terms that contain posts that in turn belong to other terms?
- modify all posts of a category to “no comments allowed”
- Ordering Post 2 Post admin meta box by meta from CPT
- Create Pages from Database
- How do I write this SQL statement for Posts written in last 24 hours?
- Combine tax_query and meta_query in WP_Query
- Want to filter only parent post in admin area
- $wpdb returns no results with SELECT query on custom post type, works on default post type
- Inserting data into `post meta` table?
- using custom taxonomies on non wp table?
- Query to change custom post type with specific category
- Mass convert MySQL data entries into custom post type?
- Calculating Bayesian average for custom post type
- How to best delete orphan wp_postmeta
- Deleting Custom Post type data using mySQL command
- Custom Post Type + 20k posts = blank/404 within Admin edit.php [duplicate]
- Adding custom tables to WordPress
- Add meta value to custom post type on publish
- convert custom query to wp_query
- using $wpdb to get custom post type with term
- Converting the_content string to an array?
- Display custom fields from custom posts in RSS feed
- Assign External Database Queries to Global Variables and Make Them Accessible
- How to import a custom MySQL DB table into a WordPress custom post type
- Get terms that contain posts that in turn belong to other terms?
- Function causing the loop display posting more (empty)
- wp_insert_post sometimes fails after API call
- Save custom post type to external database
- $post not working working in AJAX plugin with custom post type
- Proper way to display latest 5 posts grouped by post type?
- WPDB for post count on post
- Front end access to a SQL data repository – recommended way?
- Navigate posts with different post type that are in the same categories
- $wpdb->get_col and ORDER BY?
- Update post if exist from PHP
- I’m trying to create a custom version of the wp_list_authors function that includes custom post types
- New post from database
- foreach loop inside the loop creating duplicates in output
- Convert Custom Taxonomy Posts to Normal Posts
- How to import database table as custom post type and custom fields?
- SQL query – get ids – Advanced Custom Fields / WPeC
- Why doesnt my tag page populate with this custom post type?
- Fetch data of 2 relational Custom Post in WordPress
- See if the email exists or not
- How to select custom posts thats are tagged with multiple taxonomies using wpdb
- Does this archive template part look like its making too many calls to the db?
- Filter in Custom post type to find the parent post
- Custom post type and custom taxonomy key lenght & query performance
- Why is this function so slow?
- Sql Update CPT from publish to draft and particular custom field
- Dropwdown: Get taxonomy terms from posts that share preselected terms from 3 other taxonomies
- How to store additional data that is related to core data
- Update 2 wordpress tables at once
- Post that populates itself (almost) automatically using data from imported excel file
- How to use costum database table for custom post type
- Populate custom post type/custom fields from an external database
- Custom post order when using OR relation
- Custom Post save causes 500 error
- Shared Custom post type between WP network sites
- Query Distinct Taxonomies of Custom Post Type
- Adapting plugin for custom post type?
- Retrieve post data via WPDB class
- $wpdb returns no results with SELECT query on custom post type, works on default post type
- Problem with a query in custom posts
- Filtering problem
- Saving custom metabox data with a twist
- Trying to display posts by authors in with specific user meta
- Assign a tag to custom post type using a query
- Add category base to url in custom post type/taxonomy
- Removing parent slug from URL on custom post type
- Custom post types and permalink
- Custom post types, taxonomies, and permalinks
- Show MySQL errors that occur when I excute $wpdb->insert()
- Why is my select meta data not saving?
- Create a custom post with custom post-metadata with WP API
- General advice on addressing content-centric pages
- get_post_type is always post
- Different options per post type in WP_Query
- Custom post types and custom variables — add_rewrite_tag() not working
- custom post type template changes between preview and publish
- custom taxonomy pagination 404 error
- ACF Pro Accessing fields on a Custom Post Type
- add_rewrite_rule wordpress ignoring url pattern, wp rewrite not working
- How do I change the visible tables in the CPT dashboard?
- Is there a best practice, or typical way to do AJAX updating for data on a custom admin screen or post.php?
- I can not call the categories of custom post type
- Filter a custom taxonomy from displaying a button all other taxonomies can show
- Order by post meta value gets random results
- Custom post type – two taxonomies
- Order Custom Posts by Several Fields
- How to change the default orderby from “Date” to e.g. “Title” or my custom column in content type records list in admin?
- How to make an admin create/edit post page to look like taxonomy page?
- Looping taxonomy in taxonomy?
- admin search of pages returns custom post types
- Dynamically count the number of custom post types associated to a custom taxonomy