Articles of update post meta

Custom Post Type, Saving Multiple Checkboxes

For a custom post type, I’m pulling in a list of another custom post types that I need to select for saving … <input type=”checkbox” name=”32″> My CPT <br> <input type=”checkbox” name=”41″> My CPT 2 <br> <input type=”checkbox” name=”42″> My CPT 3 <br> <input type=”checkbox” name=”43″> My CPT 4 It’s easy enough to save a […]

Change the post date from a meta box

I’m having a problem with updating the post_date in a custom function I’ve written. I’m trying to change the “post_date” to my custom “meta_date” value. Here is the function: function cfc_reset_postdate( $data, $postarr ) { // If it is our form has not been submitted, so we dont want to do anything if(defined(‘DOING_AUTOSAVE’) && DOING_AUTOSAVE) […]

Change post thumbnail using front end post edit form

I’m trying to get the post thumbnail to change if a user selects a new file on a front end post edit screen. This is similar to the code I use to upload data and set the post thumbnail on a front end add new post form: <?php $query = new WP_Query( array( ‘post_type’ => […]

How to use wp_insert_post to update meta box?

I’m trying to use wp_insert_post to create a front-end submission form so visitors can create a post AND update the meta box fields of that post — not the custom fields. For example, when I use the following in the submission form… <?php update_post_meta($post_id, $meta_key, $meta_value); ?> …it updates the built-in custom field section of […]

Best way to save postmeta

Just wondering what the best way to save postmeta is. I don’t want empty postmeta values clogging up the database. I had already been saving postmeta in my plugin, which was adding empty values, so I’d like to clean those up as people re-save their posts. Any opinions on doing it like this? Improvements?: if […]

Making WordPress author follow button, need missing ingredient

So i’m trying to make a follow button in wordpress where users can press a button that allows them to follow an author they like. (No, i’m not interested in buddypress) What i’ve done so far is use the code from Jon Masterson’s Post Like System for WordPress http://hofmannsven.com/2013/laboratory/wordpress-post-like-system/ which pretty much adds a +1 […]

update_post_meta and update_field ony working when saving the post

I use Advanced Custom Fields (ACF) to store data in a custom field. I had latitude and longitude information stored separately, but I they need to be in one custom field so I made the function below. $query just queries all the relevant posts. <?php $query = query_custom_posts(); if($query->have_posts()): while ($query->have_posts()): $query->the_post(); if(get_field(‘map_lat’) && get_field(‘map_lng’)): […]

How to update_post_meta value as array

I created new custom field within my nav menu items as multiple select options i used update_post_meta() as below function YPE_update_custom_fields($menu_id, $menu_item_db_id, $menu_item_data) { if (is_array($_REQUEST[‘menu-item-content-multiple’])) { update_post_meta($menu_item_db_id, ‘_menu_item_content_multiple’, $_REQUEST[‘menu-item-content-multiple’][$menu_item_db_id]); } } add_action(‘wp_update_nav_menu_item’, ‘YPE_update_custom_fields’, 10, 3); function YPE_setup_custom_fields($item) { $item->content_multiple = get_post_meta($item->ID, ‘_menu_item_content_multiple’, true); return $item; } add_filter(‘wp_setup_nav_menu_item’, ‘YPE_setup_custom_fields’); Then I add new field into […]

How to update single value in multi dimensional Post Meta?

There are some values in Post Meta Data stored as a multi dimensional array. I want to update some of their data. Here is the Post Meta value displayed using <?php the_meta(); ?> voter: a:1:{s:5:”voter”;a:5: {s:7:”post_id”;s:6:”219585″;s:8:”voter_id”;s:4:”1540″;s:8:”voter_ip”;s:13:”182.4 8.238.86″;s:9:”author_id”;s:4:”1540″;s:4:”vote”;s:1:”1″;}}, a:1:{s:5:”voter”;a:5: {s:7:”post_id”;s:6:”219585″;s:8:”voter_id”;s:3:”832″;s:8:”voter_ip”;s:13:”182.48 .238.86″;s:9:”author_id”;s:4:”1540″;s:4:”vote”;s:2:”-1″;}}, a:1:{s:5:”voter”;a:5: {s:7:”post_id”;s:6:”219585″;s:8:”voter_id”;s:2:”10″;s:8:”voter_ip”;s:13:”182.48. 238.86″;s:9:”author_id”;s:4:”1540″;s:4:”vote”;s:1:”1″;}} Now I want to update the vote or voter_ip where user_id is […]

Efficient way to save a lot of meta data

im currently developing a plugin that will read an external xml, and convert the data to a custom post type. Each post needs around 50-60 meta_fields. Right now im looping through each piece of needed data in the xml and running a update_post_meta() on each of them. This turns out to be very inefficient because […]