• Resolved aledan

    (@aledan)


    First, thanks for your great plugin.

    I’m trying to get CPT-onomies terms of a post with “publish_post” action. But $terms varialble is always empty.
    What’s wrong?

    add_action( 'publish_custom_post', 'custom_function' );
    
    function custom_function ($post_id) {
        $post = get_post($post_id);
        $value = $post->post_modified;
        $terms = wp_get_object_terms($post->ID, 'cpt_taxonomy');
        foreach ($terms as $term) {
            add_post_meta($term, 'custom_meta_field', $value, false);
        }
    }

    https://www.ads-software.com/extend/plugins/cpt-onomies/

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter aledan

    (@aledan)

    [UPDATE]
    After post publishing, if I set the post status to draft and then publish it again the function work and I got the terms.
    How I can fix it?

    Thread Starter aledan

    (@aledan)

    [UPDATE]
    Got it working with “save_post” action. Isn’t what I want, but can do the trick.

    Are you only wanting to retrieve the terms when a post is published? Or are you wanting to get the terms whenever a post is updated/saved (which includes when it’s first created)?

    Thread Starter aledan

    (@aledan)

    When a post is published is better than updated/saved.
    I’m looping custom post type to show taxonomy terms.
    But I need to order them regarding to the last updating (I mean latest post tagged with CPT-onomies term).

    Anyway, “save_post” action does the trick, but seems that publish_[custom_post_type] action doesn’t.

    Thanks

    I’m not sure that “publish_[custom_post_type]” is an actual action. I did some searching and couldn’t find it. I could be missing it though.

    The plugin saves the CPT-onomy terms on the “save_post” action, with a priority of 10 (although I’m thinking about increasing the priority). As long as your “save_post” action comes after 10, you should be ok.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘[Plugin: CPT-onomies: Using Custom Post Types as Taxonomies] CPT with publish_post action’ is closed to new replies.