wp_dropdown_categories in custom post type with custom taxonomy

get post id $post_id=get_the_ID(); get selected region $terms = wp_get_post_terms( $post_id, $taxonomy ); $selected_id=”; if(isset($terms[0]->term_id)){ $selected_id=$terms[0]->term_id; } build hierarchical dropdown wp_dropdown_categories( array( ‘show_option_all’ => ‘Choose a region’, ‘show_option_none’ => ”, ‘orderby’ => ‘ID’, ‘order’ => ‘ASC’, ‘show_count’ => 0, ‘hide_empty’ => 0, ‘child_of’ => 0, ‘exclude’ => ”, ‘echo’ => 1, ‘selected’ => $selected_id, ‘hierarchical’ … Read more

Query custom post type by custom field

You got it pretty close. Here’s a working example of what you’re trying to do: class Wpse_126374 { public function __construct() { add_action( ‘init’, array( $this, ‘rewrites’ ) ); add_action( ‘pre_get_posts’, array( $this, ‘pre_get_posts’ ) ); } public function rewrites() { add_rewrite_tag( ‘%parent_id%’, ‘(\d+)’ ); } public function pre_get_posts( $query ) { // Don’t run … Read more

Proper way of making custom post type landing page or archive page

For this situation, I create a custom page template, say tpl-archive-page.php. For example using Advanced Custom Fields and the Post Type Selector Field(*) the user can choose a post type to connect to. <?php /** * Template Name: CPT Archive Page */ get_header(); while (have_posts()) : the_post(); get_template_part(‘content’, ‘page’); $archive_query_post_type = get_post_meta(get_queried_object_id(), ‘cpt_archive_query_post_type’, true); if( … Read more

custom post type and custom taxonomy permalink

Something similar to this in your functions.php or a plugin will do the trick: function custom_rewrite( $wp_rewrite ) { $feed_rules = array( ‘([^/]+)/cases/([^/]+).html’ => ‘index.php?genre=”. $wp_rewrite->preg_index(1) .”&case=”. $wp_rewrite->preg_index(2) ); $wp_rewrite->rules = $feed_rules + $wp_rewrite->rules; } // refresh/flush permalinks in the dashboard if this is changed in any way add_filter( “generate_rewrite_rules’, ‘custom_rewrite’ ); You will need … Read more

Duplicating custom post type and its posts

Backup your database You can do this pretty easily. I created a proof-of-concept for you to try out. I would backup the database before running this. Run the plugin Configure the plugin by setting $post_type_1 and $post_type_2 variables to your source and destination post types. To run this plugin, you need to be logged in … Read more