• 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?

    https://www.ads-software.com/plugins/posts-to-posts/

Viewing 1 replies (of 1 total)
  • If you want to pass a Taxonomy argument, you have to use tax_query instead of meta_query. You can see details at: https://codex.www.ads-software.com/Class_Reference/WP_Query#Taxonomy_Parameters

    You should try:

    'taxonomy' => 'property_type',
    'field' => 'slug',
    'terms' => 'industrial'

    Important: tax_query is an array of arrays! Remember that.

    Moreover, as you can see there is no order or orderby parameters in tax_query or meta_query, as those go in the main level hierarchy of the parameters.

    Hope this helps. Reply if you get this to work or if you need to go deeper. ??

Viewing 1 replies (of 1 total)
  • The topic ‘Is it possible to filter custom posts via custom Taxonomy?’ is closed to new replies.