WP_Query on “property” in the options table
WP_Query on “property” in the options table
WP_Query on “property” in the options table
@Milo found that the problem was with the code to order by the track number taxonomy. I’m going to make track number a custom field.
For the record I found an answer to this question in the end – I needed to use a meta query rather than a taxonomy query. The correct code ended up being this: $relatedBlogPostArgs = array( ‘post_type’ => ‘post’, ‘post_status’ => ‘publish’, ‘posts_per_page’ => 1, ‘order’ => ‘DESC’, ‘orderby’ => ‘date’, ‘meta_query’ => array( array( … Read more
You can get the Packages of the current Proposal using wp_get_object_terms() and then pass some/all of those into a WP_Query. $terms = wp_get_object_terms( $post_id, ‘packages’, array( ‘fields’ => ‘ids’ ) ); $args = array( ‘post_type’ => ‘proposals’, ‘tax_query’ => array( array( ‘taxonomy’ => ‘packages’, ‘terms’ => $terms ) ), ); $related = new WP_Query( $args … Read more
While I can’t guarentee that this is what you are looking for (as you have not posted what your expected output should be), hopefully this will help. Even if it’s not exactly what you are looking for, you have the whole object for each term available to you so that you can manipulate the output … Read more
I’m not sure how you set up looks, but it does seem that you have a lot of taxonomies registered to your post type, so I don’t think it will be very viable to use the the exclude parameter in get_terms() to exclude the specific term. What I would suggest is, inside your foreach loop … Read more
Ok I find a solution. I use posts_where filter in pre_get_posts. With this filter I can remove the term related WHERE part from the default SQL query. function custom_loops($query) { if (is_tax( ‘service_photo_location’ )){ $query->set( ‘posts_per_page’, 10); $query->set( ‘post__in’, $ids); $query->set( ‘orderby’, ‘title’); $query->set( ‘order’, ‘ASC’); add_filter( ‘posts_where’, function ( $where ) { $where = … Read more
If you use those custom fields only for the company tagged posts, then it’s sufficient to retrieve the custom fields without worrying about posts and tags: $tags = array(‘Professional Rating’, ‘Efficiency Rating’, ‘Referral Rating’); foreach ($tags as $tag) { $result = $wpdb->get_col( “SELECT meta_value FROM wp_postmeta WHERE meta_key = ‘$tag'” ); $avg = empty($result) ? … Read more
You can use this code for getting number of posts in a taxonomy: $args = array( ‘post_type’ => ‘post’, ‘post_status’ => ‘publish’, ‘posts_per_page’ => -1, ‘tax_query’ => array( array( ‘taxonomy’ => ‘your-taxonomy-name’, ‘field’ => ‘slug’, ‘terms’ => ‘some-slug’, ) ) ); $query = new WP_Query( $args ); echo $query->post_count;
I managed to sort the problem out myself with a fresh set of eyes but thought it would be useful for others if they find themselves with a similar issue in future. If the answer needs tidying please feel free to suggest any edits. I had to edit a few lines of code in order … Read more