Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 354 Vote(s) - 3.45 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Query posts by custom taxonomy ID

#1
I have a custom post type called `portfolio` and a custom taxonomy called `build-type` (acting as categories)

I am trying to query `portfolio` posts by `build-type` ID e.g. all Portfolio posts in "Hotels" (id=4 for that taxonomy)

// gets the ID from a custom field to show posts on a specific page
$buildType = get_post_meta($post->ID, 'build_type_id', true);
// run query
query_posts(array(
'post_type' => 'portfolio',
'showposts' => -1,
'tax_query' => array(
'taxonomy' => 'build-type',
'terms' => $buildType,
'field' => 'term_id'
),
'orderby' => 'title',
'order' => 'ASC'
));



Currently it's calling **all** `portfolio` posts and not just those with the `build-type` ID

For `'field' => 'term_id'` should I be using `term_id`, `tag_ID`, `id` or something else?

Anyone know how to get this working?

Thanks in advance!
Reply

#2
I'm not a WP-gury and I have invested hours and hours trying to solve the same problem. Eventually I found this blog post:

[To see links please register here]


The answer is somewhat semi-bad: apparently you can't filter like this for custom post types (it is only possible for posts), which is a shame!

What I did work was this:

$args['custom_tax'] = 'custom_tax_slug';
query_posts($args);

Hope it helps!

//Mike
Reply

#3
I solved it with help from:

[To see links please register here]


`tax-query` needs to be an array of arrays

The final solution is:


// gets the ID from a custom field to show posts on a specific page
$buildType = get_post_meta($post->ID, 'build_type_id', true);
// run query
query_posts(array(
'post_type' => 'portfolio',
'showposts' => -1,
'tax_query' => array(
array(
'taxonomy' => 'build-type',
'terms' => $buildType,
'field' => 'term_id',
)
),
'orderby' => 'title',
'order' => 'ASC' )
);

On github here:

[To see links please register here]

Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through