Displaying related posts in a custom post type by a custom taxonomy

If you want to query for multiple taxonomy terms you can use the more advanced, tax_query argument of WP_Query queries. For instance //Get array of terms $terms = get_the_terms( $post->ID , ‘product_tags’, ‘string’); //Pluck out the IDs to get an array of IDS $term_ids = wp_list_pluck($terms,’term_id’); //Query posts with tax_query. Choose in ‘IN’ if want … Read more

Custom post type loop split/ordered by taxonomy

Check the below code- // Initiating shortcode. Place this code to any of your page to get your desired output. add_shortcode( ‘faq_page_content’, ‘the_dramatist_faq_page_content’); /** * Rendering function */ function the_dramatist_faq_page_content() { $terms = get_terms(‘sections’); // Taxonomy name echo ‘<ul>’; foreach($terms as $term) { $posts = get_posts( array( ‘post_type’ => ‘questions’, // Post type ‘tax_query’ => … Read more

Assign category to front end post

I checked and it works with this: $new_post = array( ‘post_content’ => $_POST[‘post-content’], ‘post_title’ => wp_strip_all_tags( $_POST[‘post-title’] ), ‘post_type’ => ‘custom_pt’ ); note: I used a text input for the single category <input id=”input-name-value” name=”input-name-value” type=”text” /> I havent tried it with a select – option dropdown. or more than 1 category. $post_id = wp_insert_post( … Read more

Allow duplicate slugs for posts on Custom post type in different categories/taxonomy?

A simple solution would be to use a single hierarchical post type instead of a taxonomy/non-hierarchical post type combination. A hierarchical post type allows you to assign a parent post to each post. For an example you can test immediately, the built-in post post type in WordPress is non-hierarchical, the built-in page post type is … Read more

Sort custom post types by last name in the backend

If you want to override the default- and the title ordering, and order instead by the last word in the title. /** * Override default- and title ordering in the backend, for the ‘speaker’ custom post type. * * @link https://wordpress.stackexchange.com/a/202154/26350 */ add_action( ‘pre_get_posts’, function( \WP_Query $q ) { if ( is_admin() && $q->is_main_query() && … Read more

Display posts of child category in template

I have searched, and searched, and tried, and finally found…….. <?php global $wpdb; $categories = $wpdb->get_results(“SELECT $wpdb->terms.term_id AS id, name, description from $wpdb->terms INNER JOIN $wpdb->term_taxonomy ON $wpdb->terms.term_id = $wpdb->term_taxonomy.term_id WHERE parent=”$cat” ORDER BY name ASC”); foreach($categories as $category) : ?> <h2><?php echo $category->name; ?></h2> <ul> <li><a href=”https://wordpress.stackexchange.com/questions/147767/<?php echo get_category_link($category->id);?>”><b><?php echo $category->description; ?></b></a> Posts on … Read more