Split: Extending the custom query
-
Topic
-
Hi Jason,
I’m having trouble getting the custom queries to work with my special case. I’ve created a Manufacturer post type. I’ve also created a Photos post type and a Videos post type that can be tagged with the manufacturer’s name. So, within my single manufacturer template, I want to pull in those other custom post types based on whether or not they were tagged with that manufacturer name.
In my template, the following code will work.
$term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) ); global $query_string; parse_str($query_string, $args); $args=array( 'product-manufacturer' => $term->slug, 'post_type' => 'video', 'post_status' => 'published', 'order' => 'ASC', 'order_by' => 'title', 'posts_per_page' =>-1 ); $temp = $wp_query; $wp_query = null; $wp_query = new WP_Query(); $wp_query -> query ($args); while ($wp_query -> have_posts()): $wp_query ->the_post(); ?><div id="<?php post_type_archive_title();?>"><h2><?php post_type_archive_title();?></h2><?php the_content(); ?> </div> <?php endwhile; $wp_query = null; $wp_query = $temp;
But, I want to use a grid layout for the photos and videos. So, I tried this in my functions file:
/** * Custom query for Photos on single Manufacturer pages */ function custom_manufacturer_photos( $query, $args ){ if( $args['query'] == 'manufacturer_photos' ){ $term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) ); $query = array( 'post_type' => 'photo', 'product-manufacturer' => $term->slug, 'post_status' => 'publish', 'orderby' => 'title', 'order' => 'ASC', 'posts_per_page' => -1, ); } return $query; } add_filter( 'themeblvd_posts_args', 'custom_manufacturer_photos', 10, 2 );
And, this in my template:
echo do_shortcode('[post_grid query="manufacturer_photos" link="false"]');
But, getting the term by the post’s slug isn’t working. How do I achieve this?
- You must be logged in to reply to this topic.