Hot answers tagged

10

To generalize this is issue of retrieving all terms of taxonomy A that posts with specific term of taxonomy B have. While this is not impossible in several steps and plenty of looping through posts (which will indeed be inefficient), I think it's reasonable to go through SQL for efficiency. My rough take on it would be: /** * Get all terms of $tax_to ...


5

You can do this with just get_terms - this allows you to fetch all (or some) of the terms from one (or more) taxonomies. By default it excludes 'empty' terms, so you'll need to set the arguments appropriately. //Array of taxonomies to get terms for $taxonomies = array('category','post_tags','my-tax'); //Set arguments - don't 'hide' empty terms. $args = ...


4

Wordpress doesn't have the option to add extra information to taxonomies. There isn't any taxonomy_meta table. So, you have two options. Create a new custom table and save the extra information(image link) there. You can also use options table to store the information. You can follow this post of as it shows how to implement what you are trying to do: ...


3

You can try getting all the posts IDs from the first taxonomy $objects = get_posts( array( 'category' => 'history', 'numberposts' => -1, ) ); foreach ($objects as $object) { $objects_ids[] = $object->ID; } Then get the terms from the second taxonomy associated with them: $collections = wp_get_object_terms( $object_ids, 'collections' );


3

If I follow your question correctly you could use a nested query loop, that is looping through your taxonomy terms and then doing a WP_Query loop for each one. There is a more complicated approach using custom SQL and a filter but the following example is what I would go for: $terms = get_terms("locations"); $count = count($terms); if ( $count > 0 ){ ...


3

like other times, after posting here i found my own question. Maybe its not the smarter solution but its working for me. Im using the new tax_query as commented in http://www.wpmods.com/query-multiple-taxonomies-in-wp-3-1/ Basically if i get 2 taxonomies with two terms for example $job_type='full-time+free-lancer'; $job_cat='designer+programmer'; I do ...


2

I'm sure that a custom sql query would work much better but here is an option using the WordPress Tools available //first get all categories $categories = get_terms( 'category', array( 'orderby' => 'count', )); //then create an array for easier processing foreach ( $categories as $cat ) { $slugs[] = $cat->slug; $counts[$cat->...


2

I am a little fuzzy on specifics of technical side, but I think general outline would be following: Interface - you will need to either submit this as form by button or JavaScript. Query variables - you will need to register custom variable(s) via query_vars filter so your custom data is not discarded from URL. Query - modify query to make complex query, ...


2

I contacted Scribu because his Query Multiple Taxonomies plugin did what I was looking to do and he pointed me in the right direction. I've got this working (in my dev environment) so I think this is it. (Scribu had these split into two functions as part of a class - I'm sure that's the "classy" (pun unintended) way to do it - but this works inline: (Posting ...


2

You could take the query var and programatically expand the numbers between your minimum value and maximum value. Assuming http://tax.jenswedin.com/age/10,20/ is rewritten to http://tax.jenswedin.com/?age=10,20, then (pseudo code) $parts = explode(get_query_var('age'), ','); $min_val = $parts[0]; // Should be 10 in this example $max_val = $parts[1]; // ...


2

I'm not sure that there is a way to get it to use 'OR' instead of 'AND'. Alternatively, you can do: $myquery['tax_query'] = array( 'relation' => 'OR', array( 'taxonomy' => 'regions', 'terms' => array('region1'), 'field' => 'slug', 'operator' => 'IN' ), array( 'taxonomy' => 'population'...


2

I'm not sure if this the best method, and I would like to hear some other suggestions! This will alter the template to some pre-defined template if two or more taxonomies are being queried. You can hard-code the taxonomies to check or use get_taxonomies: /* * Checks to see if more than one of (certain) taxonomies are being queried * If they are, alters the ...


2

I would just retrieve an array of alphabet/taxonomy terms that have posts. You do this, but doesn't actually use it. This function will return an array of non-empty (alphabet) terms: (Transient? - unless you have multiple post types using this taxonomy, (see below) I'm not sure if much is gained from using transients - and you can just call to get_terms and ...


2

It would make more sense for the sections to be child terms below each chapter. See my answer to the similar question you referenced as well as MikeSchinkel's explanation of hierarchical taxonomies. Using the the term_id returned from get_terms use get_term_children to get the sections associated with each chapter.


2

This generalisation of above worked for me: $args = array( 'cat' = -1 ); // e.g. to get list of posts in any category $postobjs = get_posts( $args ); $postids = wp_list_pluck( $postobjs, 'ID' ); $taxonomy = 'mytax' // your taxonomy name $termobjs = wp_get_object_terms( $postids, $taxonomy ); $termlist = array_unique( wp_list_pluck( $termobjs, 'name' ) ); // ...


1

If you're in the loop, simply use get_categories().


1

I noticed your your meta key is 'wpcf-paid' which would suggest you're using Types to create custom fields. If I'm wrong, disregard the rest of this message... I had a very similar query using a value from a custom field checkbox created with Types where I also just needed to retrieve the 1 or 0. Since Types is reluctant to make things easy outside the ...


1

You have 'terms' => 'terms' => get_terms( 'brands', array( 'fields' => 'ids' ) ), when it should be 'terms' => get_terms( 'brands', array( 'fields' => 'ids' ) ), Unless that is a typo when adding your code example?


1

Three suggestions: 1. Create Your Own Metabox This is your original idea: when creating/editing the Store post type, the metabox will display a dropdown with all the available Managers of this post type. For that, use Bainternet's answer to this Question as a starting point, and change the get_categories for a get_posts of your CPT. This will be stored as ...


1

When the question comes to what to use Post Type, Taxonomies, custom fields ? I find that the understanding what each one of them stands for helps make the selection easier so i use: Post types - for all major data records that need/not to be displayed or queried. Taxonomies - for grouping posts/custom records together (with children) , helps a lot in ...


1

This helper function will return the ID of the term you are currently viewing (from any taxonomy - you can limit just to a specific taxonomy, or the built-in tag and category taxonomies). It will return false if you are not on a taxonomy term archive page. function wpse52578_get_current_term_id(){ if( !is_tax() && !is_tag() && !...


1

In the_loop, just add this code... <?php $cats = wp_get_object_terms(get_the_id(), 'category'); ?> Print_r $cats, it will have the list of the categories applied to this post.


1

I think you're on the right track because wp_get_object_terms() can take an array of IDs for its first argument, it's just that $wp_query is not the array you want. I can't guarantee that this is more efficient (not my area of expertise), but I believe this [partially-tested] snippet would do what you want with at least one fewer loop and no array_unique(): ...


1

I didn't use the transients API yet but in this case I think it's a good choice. You use it but only for a small part of the data. To cache artists per alfa and genre you could do something like this (I assume): if ( false === ( $has_artists = get_transient( "bam_artist_$i_$genre" ) ) ) { $has_artists = get_posts($termquery); set_transient( "...


1

Nothing stands out as 'wrong' - though you do have a few errors: The third tax_query conditional is missing a closing bracket The third tax_query should be querying precio not $ubicacion. Cast the ID variables as integers I'd suggest putting WordPress into debug mode to highlight any syntax errors. Try doing it for only one taxonomy first, and then add ...


1

ok, this is old and you have a solution, but i was trying to do the same thing. here is how i ended up doing it w/ SQL voodoo patched together from a couple of places, but mostly: Using wp_query is it possible to orderby taxonomy? and how to group custom post type posts by custom taxonomy terms first the query voodoo: function wpa_38075( $clauses, $...


1

I could’t make it to work. May be it is not possible. I tried a plugin to set it and I was able to achieve /%issue_name%/%post_type%/%post_id%/ but not /%issue_name%/%post_type%/%post_name%/ The plugin removes that latter one by itself. Moreover I would strongly advise against such a permalink structure as it gets very taxing on WordPress performance with ...


1

There is no simple way to do this via WP_Query(). Depending how many categories you have, the following may not be a good idea. If you have ~20 you may be ok. So, instead of saying "all posts excluding ones in 37", you would do "get me everything in all terms (not specifying term_id 37"). To do this you need to use a category__in for all your other ...


1

no idea if this would work as i don't have enough custom tax terms locally to test this right now, but what if you change the AND relation to OR ? edited b/c i was reading in the comments at : http://ottopress.com/2010/wordpress-3-1-advanced-taxonomy-queries/ that what you are asking is pretty much impossible. however, you could maybe query all audio ...


1

I guess its because you are trying two conditions on one taxonomy, you can allways create a custom sql query, something like this: $querystr = " SELECT * FROM $wpdb->posts LEFT JOIN $wpdb->term_relationships ON($wpdb->posts.ID = $wpdb->term_relationships.object_id) LEFT JOIN $wpdb->term_taxonomy ON($wpdb->term_relationships....



Only top voted, non community-wiki answers of a minimum length are eligible