admin管理员组文章数量:1391964
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' );
本文标签: loopgetpagebytitle not working inside fucntionsphp
版权声明:本文标题:loop - get_page_by_title not working inside fucntions.php 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744660576a2618220.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论