How to add automatically keyword to taxonomies when a post published, and assign them to the post

You would use the save_post hook, in your hooked function use wp_insert_term as described here: http://codex.wordpress.org/Function_Reference/wp_insert_term Then use wp_set_object_terms on the post to assignt he taxonomy term you just created as follows: http://codex.wordpress.org/Function_Reference/wp_set_object_terms for example: function my_save($post_id) { wp_insert_term( ‘bannanapost’, ‘fruit’); wp_set_object_terms( $post_id, ‘bannanapost’, ‘fruit’, true ) } add_action(‘save_post’,’my_save’); The above code, placed in functions.php … Read more

Can I limit this meta box to a particular page?

Inside your add_meta_boxex hook callback function, you will have an add_meta_box() call. Wrap that call in a conditional, using data from the $post global (I’m fairly certain it is available in edit.php). For example, you could use either the Page ID or slug. Page ID: global $post; if ( ‘123’ == $post->ID ) { // … Read more

Populating meta box with select-list of existing posts, and assigning it to custom post types

I believe this is what you were looking for. I moved back to using a class because what you were using would very easily conflict with someone else’s code who decided to use the function names select_box_add_meta_box(), select_box_content() and/or select_box_save_postdata(), which is reasonably likely. The class name WPSE_85107 is only likely to conflict with somebody … Read more

How to sort CPT by custom meta value (date), and return posts month by month

This isn’t complete copy/paste code, but hopefully it’s understandable enough to get you started. First step is to register your post type and add a rewrite rule to handle years/months. This will give you single events at event/post-name/, your post type archive at calendar, and handle incoming requests for calendar/yyyy/mm/. Make sure to visit your … Read more

Order custom posts by a date metabox

When you’re saving the data on your custom post type you need to set it so that the meta box value is actually stored as a UNIX timestamp, eg: if(!isset($_POST[“event_informations_date”])) { return $post; } else { $event_as_timestamp = strtotime ( $_POST[“event_informations_date”]; update_post_meta($post->ID, “event_informations_date”, $event_as_timestamp ); } This way you will have an orderable value for … Read more

Save selected item from dropdown menu in a meta box as a metadata value for a custom post type

$myterms = get_terms($taxonomies, $args); returns an array of term objects. Use $term->term_id as option value … “<option value=”$term->term_id”>”. esc_html( $term_name ) . “</option>” … and store that ID, not the name. Names can change, the IDs will stay the same – unless someone deletes a term and creates a new one with the same name. … Read more

Custom field being erased after autosave

I use the following code to prevent updates of my custom fields during auto-saves, ajax requests (quick edit) and bulk edits. add_action(‘save_post’, ‘save_my_post’); function save_my_post($post_id) { // Stop WP from clearing custom fields on autosave, // and also during ajax requests (e.g. quick edit) and bulk edits. if ((defined(‘DOING_AUTOSAVE’) && DOING_AUTOSAVE) || (defined(‘DOING_AJAX’) && DOING_AJAX) … Read more

Custom field values get deleted

Check your variables before you work with them. Your save function gets a parameter $post_id. Use it. From my meta box class for a check box: /** * Saves the content to the post meta. * * @return void */ public function save( $post_id ) { $this->is_allowed_save( $post_id ) and update_post_meta( $post_id, $this->vars[‘key’], empty ( … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)