Support

Account

Home Forums Backend Issues (wp-admin) custom category

Helping

custom category

  • I have created a category with this code

    
    function custom_post_type() {
    
    // Set UI labels for Custom Post Type
    $labels = array(
    'name'                => _x( 'products', 'Post Type General Name', 'twentythirteen' ),
    'singular_name'       => _x( 'product', 'Post Type Singular Name', 'twentythirteen' ),
    'menu_name'           => __( 'Products', 'twentythirteen' ),
    'parent_item_colon'   => __( 'Parent Product', 'twentythirteen' ),
    'all_items'           => __( 'All products', 'twentythirteen' ),
    'view_item'           => __( 'View Product', 'twentythirteen' ),
    'add_new_item'        => __( 'Add New Product', 'twentythirteen' ),
    'add_new'             => __( 'Add New', 'twentythirteen' ),
    'edit_item'           => __( 'Edit Product', 'twentythirteen' ),
    'update_item'         => __( 'Update Product', 'twentythirteen' ),
    'search_items'        => __( 'Search Product', 'twentythirteen' ),
    'not_found'           => __( 'Not Found', 'twentythirteen' ),
    'not_found_in_trash'  => __( 'Not found in Trash', 'twentythirteen' ),
    );
    
    // Set other options for Custom Post Type
    
    $args = array(
    'label'               => __( 'products', 'twentythirteen' ),
    'description'         => __( 'product news and reviews', 'twentythirteen' ),
    'labels'              => $labels,
    // Features this CPT supports in Post Editor
    'supports'            => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'comments', 'revisions', 'custom-fields','tags' ),
    // You can associate this CPT with a taxonomy or custom taxonomy.
    'taxonomies'          => array( 'genres' ),
    /* A hierarchical CPT is like Pages and can have
    * Parent and child items. A non-hierarchical CPT
    * is like Posts.
    */
    'hierarchical'        => true,
    'public'              => true,
    'show_ui'             => true,
    'show_in_menu'        => true,
    'show_in_nav_menus'   => true,
    'show_in_admin_bar'   => true,
    'menu_position'       => 5,
    'can_export'          => true,
    'has_archive'         => true,
    'exclude_from_search' => false,
    'publicly_queryable'  => true,
    'capability_type'     => 'page',
    );
    
    // Registering your Custom Post Type
    register_post_type( 'products', $args );
    register_taxonomy('categories', array('products'), array("hierarchical" => true, "label" => "Categories", "singular_label" => "Category", "rewrite" => array( 'slug' => 'products', 'with_front'=> false )));
    
    }
    
    /* Hook into the 'init' action so that the function
    * Containing our post type registration is not
    * unnecessarily executed.
    */
    
    //create two taxonomies, genres and tags for the post type "tag"
    function create_tag_taxonomies() 
    {
      // Add new taxonomy, NOT hierarchical (like tags)
      $labels = array(
        'name' => _x( 'Tags', 'taxonomy general name' ),
        'singular_name' => _x( 'Tag', 'taxonomy singular name' ),
        'search_items' =>  __( 'Search Tags' ),
        'popular_items' => __( 'Popular Tags' ),
        'all_items' => __( 'All Tags' ),
        'parent_item' => null,
        'parent_item_colon' => null,
        'edit_item' => __( 'Edit Tag' ), 
        'update_item' => __( 'Update Tag' ),
        'add_new_item' => __( 'Add New Tag' ),
        'new_item_name' => __( 'New Tag Name' ),
        'separate_items_with_commas' => __( 'Separate tags with commas' ),
        'add_or_remove_items' => __( 'Add or remove tags' ),
        'choose_from_most_used' => __( 'Choose from the most used tags' ),
        'menu_name' => __( 'Tags' ),
      ); 
    
      register_taxonomy('tag','products',array(
        'hierarchical' => true,
        'labels' => $labels,
        'show_ui' => true,
        'update_count_callback' => '_update_post_term_count',
        'query_var' => true,
        'rewrite' => array( 'slug' => 'tag' ),
      ));
    }
    
    add_action( 'init', 'create_tag_taxonomies', 0 );

    How can I display the list of posts of that taxonomy using the َACF plugin’s taxonomy feature?

    https://www.advancedcustomfields.com/resources/taxonomy/

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.