How to display all CPT rows on a page
- This topic has 4 replies, 2 voices, and was last updated 5 years, 5 months ago by
John Anderson.
-
AuthorPosts
-
November 12, 2019 at 1:06 PM #16896
John Anderson
ParticipantHello,
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' );
November 12, 2019 at 2:47 PM #16900John Anderson
Participantticking notify checkbox.
November 12, 2019 at 3:03 PM #16902John Anderson
ParticipantAs 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.
November 12, 2019 at 3:13 PM #16904Anh Tran
KeymasterHave 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.
November 13, 2019 at 3:21 AM #16910John Anderson
ParticipantOh 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!
-
AuthorPosts
- You must be logged in to reply to this topic.