Can’t get post ID using wp_insert_post_data
From the codex page You must pass 2 for the $accepted_args variable in add_filter() if you want to access $postarr. So use this: add_filter( ‘wp_insert_post_data’, ‘set_post_title’, 99, 2 );
From the codex page You must pass 2 for the $accepted_args variable in add_filter() if you want to access $postarr. So use this: add_filter( ‘wp_insert_post_data’, ‘set_post_title’, 99, 2 );
Your data is being serialize properly. Your code saves an array of integers. Integers are not strings and so a string length is not saved. Run the following code and it should illustrate the point: $str=”a:4:{i:0;s:4:”7613″;i:1;s:4:”7615″;i:2;s:4:”7616″;i:3;s:4:”7618″;}”; $str = maybe_unserialize($str); var_dump($str); echo ‘<br/>’; var_dump(maybe_serialize($str)); echo ‘<br/>’; $str = array( 1234,4567,8910,1112 ); var_dump(maybe_serialize($str)); echo ‘<br/>’; $str = … Read more
In short, this is serialized data and this is how data is stored from a custom field (and many other datastrings) in the db. s:114 is auto generated and simply means that the value http://localhost/wp-content/uploads/woocommerce_uploads/2014/09/test-file.pdf is a string and is 114 characters long. This is used when the data is read and used. If the … Read more
I came across this post looking for a solution for multiple resubmissions due to update_post_meta. Here’s my solution after looking at these posts wordpress get_post_meta check if multiple values set Prevent processing data multiple times in Woocommerce thankyou hook : <?php global $post; $post = $order_id; if ( isset( $_POST[‘submit’] ) ){ echo ‘Update nicht’; … Read more
To begin with you may need to add %s to the sprintf function, as the current link has no anchor text and this is supposed to be put in by sprintf as the second argument: return sprintf( ‘<div class=”form-block block-after-indent”><a class=”atbtn atbtn–secondary1″ href=”#sime_url_product_id_%d”>%s</a></div>’, $product->id, esc_html( $product->get_title() ) );
There is no $post var local to your function, you need to use global $post first, or get_the_ID(). get_post_meta( get_the_ID(), ‘_cf_address’, true );
Just set the image alt text when the image is saved. Hook onto the save_post action, check if any of the attached images don’t have alt text, and if not then generate the alt text you want and save it with: update_post_meta( $attachment_id, ‘_wp_attachment_image_alt’, ‘this is the alt text’ );
Yes, we can use existing tables in WordPress for storing the values. Post meta fields are stored in the {$wpdb->prefix}_postmeta table (depending on the table prefix; wp_postmeta by default). If the meta key “like_count” is already present in the table along with the post ID then update_post_meta() will update this, and otherwise this function will … Read more
I found where the problem was. The code was attached to the the_content hook which runs after the thumbnail is generated. Attached the code to post_thumbnail_html and it works now.
You need to query the db using wp_query to get all the posts from the CPT, save the metabox contents to an array and then print the array. Not tested but should work (i hope): <?php $select_array = array(); $args = array ( ‘post_type’ => ‘your_cpt’, ); $query1 = new WP_Query( $args ); while ( … Read more