WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] problem with post_type on custom post type (3 posts)

  1. niceandripe
    Member
    Posted 4 years ago #

    I've created two custom post types pretty much the same

    add_action('init', 'classifieds');
    
    function classifieds() {
    $args = array(
    'label' => __('Classifieds'),
    'singular_label' => __('Listing'),
    'public' => true,
    'show_ui' => true,
    'capability_type' => 'post',
    'hierarchical' => false,
    'rewrite' => true,
    'supports' => array('title', 'editor', 'thumbnail')
    );
    
    register_taxonomy( 'classifieds-category', 'classifieds',
    array(
    'hierarchical' => false,
    'label' => __('Categories'),
    'query_var' => 'classifieds-category',
    'rewrite' => array('slug' => 'classifieds-category' )
    )
    );
    
    register_post_type( 'classifieds' , $args );
    }

    and also

    add_action('init', 'directory');
    
    function directory() {
    $args = array(
    'label' => __('Directory'),
    'singular_label' => __('Listing'),
    'public' => true,
    'show_ui' => true,
    'capability_type' => 'post',
    'hierarchical' => false,
    'rewrite' => true,
    'supports' => array('title', 'editor', 'thumbnail')
    );
    
    register_taxonomy( 'directory-category', 'directory',
    array(
    'hierarchical' => false,
    'label' => __('Categories'),
    'query_var' => 'directory-category',
    'rewrite' => array('slug' => 'directory-category' )
    )
    );
    
    register_post_type( 'directory' , $args );
    }

    however if I use
    <?php echo $post_type ?>
    they both show the same - "directory" and i can't seem to get "classifieds" for the classifieds posts?!

    ??

  2. MichaelH
    Member
    Posted 4 years ago #

    If you are talking about the post_type for a given post and you are in a "standard" loop, then $post->post_type would hold that value.

  3. niceandripe
    Member
    Posted 4 years ago #

    perfect, thanks

Topic Closed

This topic has been closed to new replies.

About this Topic