Is it possible to filter custom posts via custom Taxonomy?
-
I had a play around with using connection metadata but I found the solution inelegant. I don’t like that each new post requires a post-meta type to be selected.
Essentially I have Property CPT and Listing CPT. I have a custom taxonomy of property_type attached to property so it can be selected and Commercial or Industrial. I want to get listings associated with a Property to inherit the property_type.
Here’s my relationship:
// Set up Property and Listing relationship function my_connection_types() { p2p_register_connection_type( array( 'name' => 'posts_to_pages', 'from' => 'listing', 'to' => 'property', 'reciprocal' => true, 'sortable' => 'any', )); } add_action( 'p2p_init', 'my_connection_types' );
And this is the query I was attempting to use:
$query = new WP_Query( array( 'connected_type' => 'posts_to_pages', 'connected_items' => get_queried_object_id(), 'nopaging' => true, 'meta_query' => array( array( 'property_type' => 'industrial', 'posts_per_page' => '4', 'order' => 'DESC', 'orderby' => 'modified', ) ) ) );
Here I’m trying to display 4 of the latest modified Listings that are of property_type industrial (the custom taxonomy attached to Property, that I was hoping I could inherit to listings).
Obviously this doesn’t work so what am I doing wrong here? Or is this even possible with the plugin?
- The topic ‘Is it possible to filter custom posts via custom Taxonomy?’ is closed to new replies.