Add post meta for custom post type on publish
-
Hello everyone,
I’m trying to add custom post meta for a custom post type on publish (or on update if the post meta doesn’t already exist). I’ve done some research, tried a bunch of things, but nothing has worked so far. The custom post type is “portfolio.” Here is my code:
function add_portfolio_position($post) { $post_id = $post->ID; add_post_meta( $post_id, '_portfolio_position', 0, true); } add_action('new_to_publish_portfolio', 'add_portfolio_position'); add_action('draft_to_publish_portfolio', 'add_portfolio_position'); add_action('pending_to_publish_portfolio', 'add_portfolio_position');
Any and all suggestions appreciated.
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Add post meta for custom post type on publish’ is closed to new replies.