Answers for "wordpress get categories of custom post type"

PHP
1

wp_query get custom post type

<?php    
  	   $args = array(  
      'post_type' => 'custom_type',
      'post_status' => 'publish',
      'posts_per_page' => 8, 
      'orderby' => 'title', 
      'order' => 'ASC', 
          );

  $loop = new WP_Query( $args ); 

  while ( $loop->have_posts() ) : $loop->the_post(); 
      print the_title(); 
      the_excerpt(); 
  endwhile;

  wp_reset_postdata(); 
  ?>
Posted by: Guest on November-27-2020
1

wordpress get post type

// Retrieves the post type of the current post or of a given post.
get_post_type( int|WP_Post|null $post = null )
Posted by: Guest on February-19-2021
0

wp+custom post type with category

function custom_post_type() {
     $labels = array(
        'name'                => _x( 'Movies', 'Post Type General Name', 'twentythirteen' ),
        'singular_name'       => _x( 'Movie', 'Post Type Singular Name', 'twentythirteen' ),
        'menu_name'           => __( 'Movies', 'twentythirteen' ),
        'parent_item_colon'   => __( 'Parent Movie', 'twentythirteen' ),
        'all_items'           => __( 'All Movies', 'twentythirteen' ),
        'view_item'           => __( 'View Movie', 'twentythirteen' ),
        'add_new_item'        => __( 'Add New Movie', 'twentythirteen' ),
        'add_new'             => __( 'Add New', 'twentythirteen' ),
        'edit_item'           => __( 'Edit Movie', 'twentythirteen' ),
        'update_item'         => __( 'Update Movie', 'twentythirteen' ),
        'search_items'        => __( 'Search Movie', 'twentythirteen' ),
        'not_found'           => __( 'Not Found', 'twentythirteen' ),
        'not_found_in_trash'  => __( 'Not found in Trash', 'twentythirteen' ),
    );
     
     
    $args = array(
        'label'               => __( 'movies', 'twentythirteen' ),
        'description'         => __( 'Movie news and reviews', 'twentythirteen' ),
        'labels'              => $labels,
        'supports'            => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'comments', 'revisions', 'custom-fields', ),
        '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',
        'show_in_rest'        => true,
         
        // This is where we add taxonomies to our CPT
        'taxonomies'          => array( 'category' ),
    );
     
    // Registering your Custom Post Type
    register_post_type( 'movies', $args );
 
}
 

add_action( 'init', 'custom_post_type', 0 );
Posted by: Guest on June-27-2021
0

wp+create custom post type and category

add_action( 'init', 'create_news' );
function create_news ()
{      
    register_post_type( 'ecommerces',
                array(
                'labels'        => array(
                'name'          => __( 'Ecommerces' ),
                'singular_name' => __( 'Ecommerce' )
                ),
                'public'   => true,
                'supports' => array ('title', 'editor', 'thumbnail')
                )
                );

    register_taxonomy(
                'ecommerce_cat',
                'ecommerces',
                array(
                'labels' => array(
                'name' => 'Ecommerce Categories',
                'add_new_item' => 'Add New Ecommerce Category',
                'new_item_name' => "New Ecommerce Category"
                ),
                'show_ui' => true,
                'show_tagcloud' => false,
                'hierarchical' => true,
                'hasArchive' => true
                )
                );

    }

    if ( function_exists( 'add_theme_support' ) ) {
    add_theme_support( 'post-thumbnails' );
    set_post_thumbnail_size( 100, 100, true ); 
}

    ?>
Posted by: Guest on November-28-2020

Code answers related to "wordpress get categories of custom post type"

Browse Popular Code Answers by Language