Pagination throws 404 error on custom taxonomy archive pages

This function fixed the issue: function change_posttype() { if( is_archive() && !is_admin() ) { set_query_var( ‘post_type’, array( ‘post’, ‘portfolio’ ) ); } } add_action( ‘parse_query’, ‘change_posttype’ ); Then I just removed the paged and query_string function in my code and just left the regular loop 🙂

Filter custom post types in admin not working

Basically you are doing every thing right except the taxonomy slug in the url should be lowercase so you can simply place this line: esc_url( add_query_arg( array( ‘post_type’ => $post->post_type, ‘Service’ => $term->slug ), ‘edit.php’ ) ), with this: esc_url( add_query_arg( array( ‘post_type’ => $post->post_type, ‘service’ => $term->slug ), ‘edit.php’ ) ), and you should … Read more

How do you create an archive for a custom post type from a plugin?

Include your template files in your plugin. I stick mine in /plugin/templates. You need to hook into template location for that template: add_filter(‘archive_template’, ‘yourplugin_get_custom_archive_template’); function yourplugin_get_custom_archive_template($template) { global $wp_query; if (is_post_type_archive(‘yourCPT’)) { $templates[] = ‘archive-yourCPT.php’; $template = yourplugin_locate_plugin_template($templates); } return $template; } Rinse and repeat with the appropriate checks for each template you want to … Read more

Restrict custom post type view by user role

Every role has capabilities. Here is a simple contributor to our endeavor: (he just writes and edits) add_role(‘contributor’, ‘Contributor’, array( ‘read’ => true, ‘edit_posts’ => true, ‘delete_posts’ => false, )); Now he has a new capability (he can edit other peoples posts) function add_capability() { $role = get_role(‘contributor’); $role->add_cap(‘edit_others_posts’); } add_action(‘admin_init’, ‘add_capability’); Now to add … Read more

Display custom post type with shortcode

I think, basically your question is, how to query posts of a custom post type in a shortcode. You should have a look into the WP_Query section of WordPress: https://codex.wordpress.org/Class_Reference/WP_Query In my example code I create a shortcode, which shows the title of the latest published posts of the type ‘my-custom-post-type’: <?php add_shortcode( ‘shortcodename’, ‘display_custom_post_type’ … Read more

Numeric slug on child post

As you guessed and @Rarst suspected, there’s a pagination check in wp_unique_post_slug() for hierarchical post types: preg_match( “@^($wp_rewrite->pagination_base)?\d+$@”, $slug ) which will match any numeric only slug, optionally preceded by “page”. To get around this you could use the ‘wp_unique_post_slug’ filter, basically replicating the original code without the pagination check, eg add_filter( ‘wp_unique_post_slug’, function ( … Read more

Custom Post Type – Taxonomy Dropdown Menu?

This is how I did this. <?php $tax = get_object_taxonomies(‘TAXONOMY_NAME’); $taxterms = get_terms( $tax, ‘orderby=count&offset=1&hide_empty=0&fields=all’ ); ?> <select name=”tax” id=’tax’> <option value=”” <?php if (!count( $names )) echo “selected”;?>>Select Term</option> <?php foreach ( $taxterms as $term ) { echo ‘<option value=”‘ . $term->slug . ‘” selected>’ . $term->name . ‘</option>’,”\n”; } ?> </select>