How can update custom meta (likes) for all posts that have this meta?
If you want to update every post that has this meta:
See the returns field parameter and custom field parameters for Wp_Query
to 1) retrieve only posts with that meta_key
, and 2) to lighten query and only return the ids
instead of full objects. Then loop through them.
Something like this (untested):
$args = array( 'fields' => 'ids',
'posts_per_page' => -1,
'post_type' => 'posts',
'meta_key' => 'likes'
);
$all_ids = new WP_Query( $args );
foreach( $all_ids as $ai ) {
update_post_meta( $ai->post->ID, 'likes', 1 );
}
wp_reset_postdata();
Related Posts:
- Hide a div when a custom field is empty
- How to update custom fields using the wp_insert_post() function?
- How to automatically apply woocommerce product title to all product images alt tags?
- How to display multiple Post meta_key/meta_values by SQL query
- the_post_thumbnail() based on the Post ID
- How to use multiple query with same meta key
- Add custom field to attachments in a specific category
- Use ajax to update_post_meta
- how to increase custom post value by one most efficiently?
- How to Display Image Meta underneath EVERY image in EVERY post
- How can I create a list of page titles from custom meta values?
- Passing the custom field values in the wp_get_current_user array function
- Store multiple custom field as post meta per post(css, js, html, 2 link) [closed]
- How to VAR_DUMP a $variable during checkout process (Is my product meta callable?)
- get_post_meta not working on publishing
- Firing schema via code in functions.php doesn’t work
- 3 Slashes appear after Apostrophe in custom fields after updating product-site
- Trying to retrieve post meta
- Which PHP page is the Default Posts Page
- Is it possible to retrieve all posts with a certain value for metadata?
- Non-Closing PHP Query in WordPress Loop
- How to check if a PHP string is different than meta field?
- Can’t save php string to a custom field
- Why does this update_post_meta function not delete the custom field itself?
- How to show/hide php table rows based on the content of custom fields
- how to get serialized post meta
- Custom meta box values are not getting saved for my custom post type
- Show ACF field with link to ultimate member profile/WordPress user profile below the post (single post layout)
- WordPress loop by meta key that is an array? and how loop multiple arrays
- WP All Import / Update stock quantity from multiple XML files
- How to store multiple custom meta box
- Changing the order of custom fields in the dashboard for Woocommerce variable products [closed]
- How to add data to a custom field at the wp_users table?
- Problem with adding custom CSS class to image in ACF Photo Gallery plugin [closed]
- Order a WP_Query by meta value where the value is an array
- Add a custom class to the body tag using custom fields
- Define category ID using get_post_meta
- Unable to Call More than One Meta Box Output
- Conditional On custom field plugin metabox
- WordPress stripping out custom field tags
- How to check post meta isset or not empty during publish/save post?
- Delete images from media library when user deletes an image from ACF Gallery
- Updating Metadata with Shortcode
- Order category posts by last word of custom field
- Add a “custom field” to a category that can be retrieved when viewing the category page with get_post_meta
- Products listing check if meta checkbox is checked
- Trying to update Woocommerce meta values
- How to add and subtract user meta values after post meta update
- Is it possible to update the dataset using update_post_meta
- How to update custom fields when post is published?
- Block error message in foreach loop when looping through ACF field
- Hide a div if the fiels is empty
- Delete post meta by serialized meta value
- How do I get the value of a current user’s custom field?
- WP post meta – for loop inside for loop
- Store custom field’s multiple values in one user meta key
- Get field in readable word
- When working with a post, almost all wp_postmeta are deleted
- Updating Lat and Lng of posts automatically gives sporadic results
- Postmeta not saving
- If custom field doesn’t exist, or exists and it’s true show title?
- get_post_meta no longer working
- Display custom meta box in my template file
- ACF Date fileds to Age Convert [closed]
- Metadata on the WP_Post object
- How to display the date under the post title?
- Appending an ACF custom field to the page title
- How do I get a function to work in single.php
- How to pass value to add_filter wpcf7_form_tag from another function?
- Custom Admin Menu Report for Specific User ID
- ACF number less than comparison not working
- Is the regular ajax request method safe or I should use admin-ajax.php?
- Create an array from an array
- Shortcode return function with link href inside PHP
- Can’t get page content in WordPress
- How to call plugin function per site in a multisite?
- Display custom field on 404 page outside loop
- Pagination broken on is_front_page()
- Missing a text-domain esc_attr_e
- Execute PHP code only with specific user role
- PHP function for horizontal Woocommerce thumbnails and badges
- Is there a PHP function that will return the block ID generated by WordPress?
- Creating a Function and Call It
- WooCommerce display price before add to cart [closed]
- Show sidebar only to author of post
- how to add custom select field to wordpress edit page
- WP_query meta_query slow with OR and DATES
- meta field for numerous links
- Matching multi user
- Where can I find the declaration of `$_wp_theme_features`?
- redirect 301 with special character like WIX site “#!”
- auto metakey value on post tile
- How I can add div to menu?
- Modify category archive page loop on functions.php
- How to print redirected query string variables to the page?
- Admin-area broken through weird issues
- Check if values exists DB
- Understanding responsive imagery
- How to get meta box labels?
- Convert custom field date format to “WordPress default”