1

I have tried everything I can to filter my posts by a custom field taxonomy.

What I have is a custom field with the name of "category" with the field type of "post object", and I am listing all of my pages on my site to choose from.

When I am on my blog post I select an item from the dropdown menu, and now what I want to do is to get the specific post that has the "category" post_title of the current page I am on.

For instance:

I am on the page "Construction", and in my blog post I have selected this page from the list of pages. Now I want to find the latest blog post with the "Category" post_title of "Construction".

My code:

 $args = array(
            'posts_per_page'   => -1,
            'offset'           => 0,
            'category'         => '',
            'orderby'          => 'post_date',
            'order'            => 'DESC',
            'tax_query' => array( 
                                    array( 
                                        'taxonomy' => 'category',
                                        'field' => 'post_title', 
                                        'terms' => $pageName
                                    ) 
                                ),
            'post_type'        => 'post',
            'post_status'      => 'publish',
            'suppress_filters' => true );


        $myposts = get_posts( $args );
Dylan Cross
  • 5,918
  • 22
  • 77
  • 118
  • Hi, I try to answer your question, but I think you mix some things up. Do you have a custom field "category" or a taxonomy "post_title". Once I understand this, I think, I can help you, since I've programmed a plugin, which helps in this cases: http://codecanyon.net/item/filter-custom-fields-taxonomies/6964843?ref=websupporter – websupporter Aug 17 '14 at 18:50
  • Your taxonomy values are in a double-nested array. That might be your issue. – Aibrean Aug 22 '14 at 16:50

0 Answers0