loop - get_page_by_title not working inside fucntions.php

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 im

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

相关推荐

  • loop - get_page_by_title not working inside fucntions.php

    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 im

    1天前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信