After much reading, i realized that it would be more easily done using the WordPress API, so i baked out this little script. Simply add it to your theme’s functions.php then run it once. When done, remove it.
function convertGalleries($test){
$galleries = get_posts(array( 'meta_key' => 'custom_post_template', 'post_status' => array( 'any' ),'posts_per_page'=>-1 ));
if($test){
return count($galleries);
}
$result = array();
foreach($galleries as $g){
$result[$g->ID]= set_post_format($g->ID, 'gallery' );
}
return $result;
}
$converted = convertGalleries(false);
echo 'result: '.count($converted). ' posts converted: <pre>';
print_r($converted);
exit;
Related Posts:
- importing data from non-wordpress mysql db
- Query meta field using between
- Move value of one custom field to another
- Get multiple custom field values in a $wpdb query [duplicate]
- Difference between ‘LIKE’ and ‘IN’ in meta queries
- little help with a mySQL query to wp database
- Importing users to Buddypress with custom fields
- MySQL query to set wp_postmeta using term_taxonomy_id value
- MySQL Query that looks for post with Custom Field, then changes Category
- Unique Post Meta Values
- Add custom field to all posts in specific post_type
- UPDATE on SELECT results. A SQL query to swap Author with Meta Box value
- Importing WordPress Posts With Custom Meta Data As CSV Files Through PHPMyAdmin
- Inserting data into MagicFields using mysql queries
- Copy price categories to custom field
- If I update WordPress my custom data will be deleted from the wp_users table?
- Update post meta data (custom field) by post link
- Help setting up a sql query
- Add specific custom fields to post formats
- wpdb function insert doesn’t work
- How to improve my non-unique metadata MySQL entries?
- Delete a custom field in mysql for all posts with specific category id
- use mysql to replace one custom field value with another custom field value
- Copy url from post_content to custom field
- Custom Search, MySql Query Gone Wrong?
- Can running a WP-Cron to update_post_meta cause performance issues?
- Add a Jquery Datepicker to custom field in post edit
- How can I avoid re-inventing the Custom Fields wheel in my Plugin’s Metabox?
- Using wordpress post data as input for google visualisations
- Does wordpress have something like content-type?
- Order Posts by Closest Numeric Values
- How to get and edit custom fields if in Quick Edit
- Order posts by custom field and if custom field is empty return remaining posts
- Create additional short URL with custom field and 301 redirect
- Create custom field on post draft or publish?
- Using custom fields in a filter hook
- Adding a prefix to a post title
- Add a post meta key and value only if it does not exist on the post
- Function to change meta value in database for each post
- Sorting posts by multiple values, combined
- WP_Meta_Query causing long-running MySQL queries
- trim custom field text value and show (…)
- Duplicate posts being displayed when querying Custom Fields
- How to validate custom field on lost password form before the user id field?
- Json api does not return all metadata
- Use custom field as a variable
- ACF: How to get the full field name (meta_key) by a field key?
- Woocommerce: Custom fields and email shortcodes, ec_custom_field
- Tweak Meta for Post to work it for Pages also
- Create Pop-Up Box with Custom Field Content Inside the Loop
- Adding an editable field to template?
- Transferring author information from a custom field to a proper author
- How to select posts from multiple categories and metavalues?
- modify wordpress caption shortcode
- jQuery – Automatic event trigger does not **really** check my form
- Display URL in a Custom Field
- Linking Custom Fields to Database Records
- Stop sending email everytime I updates my post
- Best way to store everyday post views?
- Display list of terms having the same custom field value
- How to display custom field in woocommerce email orders? [closed]
- Custom meta is not being saved
- Branch made by several custom values
- How can I activate custom fields checkbox in pages?
- Can I save post meta programatically without setting metaboxes?
- Show custom field on attachment page?
- WP Insert post with post_thumbnail
- Custom meta boxes in RSS feed
- How to pass custom field value to shortcode?
- custom comment_form fields not displaying
- WP_Query () using taxonomy, custom post types
- Ordering by ‘Title’ OR ‘Custom Field’
- How can I add/update post meta in a admin menu page?
- pull all posts’ meta key values from current category only
- Searching with Multiple (Parallel) Criteria on Custom Fields?
- Save custom field types with this function…?
- Compare ACF date field (if exists) and post date and order DESC
- Add WordPress user custom meta to chartjs vertically stacked chart in Divi theme
- What am I missing in this Code Block?
- Making WP_Query limit results by date before today where date is a meta_query
- Shortcode for Custom Field of Media Attachment (to use with Featured Images)
- Trying to get custom field data in a simple plugin
- submitting form to admin-panel.php returns 500 error
- Sort columns in the ‘Pages’ dashboard overview
- Create Meta boxes dynamically
- Outputting custom field on home.php not outside of blog list
- How to delete attachments associated with custom field type when post property changes? [closed]
- I have a form with a custom button ,i want to add the field data to an database when clicking the custom button
- custom field images do not display until page save
- How to check custom fields from functions.php
- Add capability for editors to modify custom fields
- Custom Field select list is truncated
- Query Posts Via WordPress URL
- show custom field content in jquery tabs
- Create citation and url in post using 3 custom fields with conditions for each field… So close!
- Advenced custom fields auto fill problem
- Show only first image of multiple image field
- Custom Fields after update to WordPress 6
- How to apply Local Business Google Schema dynamically on a Custom Post single template?
- Match submitted array fields with the MYSQL database fields to update them correctly in PHP