How to display all CPT rows on a page

Support General How to display all CPT rows on a pageResolved

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #16896
    John AndersonJohn Anderson
    Participant

    Hello,
    I have a CPT setup to capture information about Team Members. I want to display load all of these Team Members into a page and display certain ones based on criteria. I can add the criteria later on with if statements but wonder how do I call the CPT? I know what to do with for each once I get started, but can't seem to get the syntax to load this CPT.

    The CPT is called "team-members".

    Any ideas?
    Thanks,
    John.

    
    function your_prefix_register_post_type() {
    
        $args = array (
            'label' => esc_html__( 'Team Members', 'text-domain' ),
            'labels' => array(
                'menu_name' => esc_html__( 'Team Members', 'text-domain' ),
                'name_admin_bar' => esc_html__( 'Team Member', 'text-domain' ),
                'add_new' => esc_html__( 'Add new', 'text-domain' ),
                'add_new_item' => esc_html__( 'Add new Team Member', 'text-domain' ),
                'new_item' => esc_html__( 'New Team Member', 'text-domain' ),
                'edit_item' => esc_html__( 'Edit Team Member', 'text-domain' ),
                'view_item' => esc_html__( 'View Team Member', 'text-domain' ),
                'update_item' => esc_html__( 'Update Team Member', 'text-domain' ),
                'all_items' => esc_html__( 'All Team Members', 'text-domain' ),
                'search_items' => esc_html__( 'Search Team Members', 'text-domain' ),
                'parent_item_colon' => esc_html__( 'Parent Team Member', 'text-domain' ),
                'not_found' => esc_html__( 'No Team Members found', 'text-domain' ),
                'not_found_in_trash' => esc_html__( 'No Team Members found in Trash', 'text-domain' ),
                'name' => esc_html__( 'Team Members', 'text-domain' ),
                'singular_name' => esc_html__( 'Team Member', 'text-domain' ),
            ),
            'public' => true,
            'exclude_from_search' => false,
            'publicly_queryable' => true,
            'show_ui' => true,
            'show_in_nav_menus' => true,
            'show_in_admin_bar' => true,
            'show_in_rest' => true,
            'menu_icon' => 'dashicons-businessman',
            'capability_type' => 'post',
            'hierarchical' => false,
            'has_archive' => true,
            'query_var' => true,
            'can_export' => true,
            'rewrite_no_front' => false,
            'supports' => array(
                'title',
                'thumbnail',
            ),
            'rewrite' => true,
        );
    
        register_post_type( 'team-member', $args );
    }
    add_action( 'init', 'your_prefix_register_post_type' );
    
    #16900
    John AndersonJohn Anderson
    Participant

    ticking notify checkbox.

    #16902
    John AndersonJohn Anderson
    Participant

    As if you were displaying the CPT in an Archive page. That kind of thing. But in this instance I want to control or limit which posts I display from this CPT.

    #16904
    Anh TranAnh Tran
    Keymaster

    Have you tried making a custom WP_Query with 'posts_per_page' => -1? This is what I did for the Extensions page.

    For filtering, I create another taxonomy (called tag or category) and output CSS classes based on the selected terms. For example: items within category "Free" will have a CSS class "free". Then I use some JS to filter them out.

    #16910
    John AndersonJohn Anderson
    Participant

    Oh nice. thank you. I've used WP_Query in the past but am not doing a lot at the moment and had forgotten about it.

    Thank you for the quick response and the good ideas!

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.