Retrieving list of Custom Post Types

There’s a core function for that: get_post_types(): <?php get_post_types( $args, $output, $operator ); ?> So, for example, to return public, custom post types by name: $custom_post_types = get_post_types( array( // Set to FALSE to return only custom post types ‘_builtin’ => false, // Set to TRUE to return only public post types ‘public’ => true … Read more

How does register_post_type know how and which function to use from the add_action function?

You are confusing between function and hook. register_post_type() is a function, not a hook. When you are using register_post_type( ‘book’, $args ), you are calling the register_post_type() function to create a Custom Post Type named book. register_post_type() needs to be used on the init hook which is fired at the beginning of wordpress initialisation, that’s … Read more

CPT Search Form with Taxonomy filter & Or

I think you can do it in two following steps: In HTML code just add a dropdown with the values you need. <select name=”yourselect”><option value=”1″>Value 1</option> … </select> In your pre_get_posts filter add tax_query parameter like this if( !empty( $_GET[‘yourselect’] ) ) { $query->set(‘tax_query’, array( array( ‘taxonomy’ => ‘YOUR_TAXONOMY_NAME’, ‘field’ => ‘id’, // or slug … Read more

How to create A-Z index listing for custom post types?

Ok, you just have to make a loop with first letter check. WordPress query will handle the post_title ASC order. EDIT : I use get_permalink() within the loop to get URL (https://developer.wordpress.org/reference/functions/get_permalink/) $series = new WP_Query(array( ‘posts_per_page’ => -1, ‘post_type’ => ‘series_type’, ‘orderby’ => ‘title’, ‘order’ => ‘asc’ )); if($series->have_posts()) { $letter=””; while($series->have_posts()) { $series->the_post(); … Read more