WordPress.org

Ready to get started?Download WordPress

Forums

CPT-onomies: Using Custom Post Types as Taxonomies
[resolved] CPT with publish_post action (6 posts)

  1. aledan
    Member
    Posted 2 years ago #

    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);
        }
    }

    http://wordpress.org/extend/plugins/cpt-onomies/

  2. aledan
    Member
    Posted 2 years ago #

    [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?

  3. aledan
    Member
    Posted 2 years ago #

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

  4. Rachel Carden
    Member
    Plugin Author

    Posted 2 years ago #

    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)?

  5. aledan
    Member
    Posted 2 years ago #

    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

  6. Rachel Carden
    Member
    Plugin Author

    Posted 2 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic