so here is the deal I have episodes custom post type this post type needs the id of the series to get some data like image and description etc...
Now I am using a plugin to add posts to the site and the plugin only supports custom fields with name and value. The problem is I don't know the id but I know the series name so here is what I did :
I created a custom field with the name of the series on it and do a get_page_by_title() to get the id of the series with the same title theoretically, that should work and it did when I add it on header.php and access the page then it gets executed
but that is not really practical so I tried adding it to functions.php so it would be executed after each post is published, but when I dod this code inside functions.php it does not work at all
here is the code
function set_private_categories($post_id) {
$posttitle = get_field('serie');
//$mytitle = 'The Fosters saison 4';
$mytitle2 = get_page_by_title( $posttitle, OBJECT, 'series' );
//print_r($mytitle2->ID);
update_field( 'sora_series', $mytitle2->ID, $post_id );
}
add_action( 'save_post_watch', 'set_private_categories' );
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744660576a4586436.html
评论列表(0条)