Tag Info

New answers tagged

0

This is an update of Stephen's answer based the new get_terms_by function and assuming we know what taxonomy we want. add_action('set_object_terms','save_terms',10,6); function save_terms($object_id, $terms, $tt_ids, $taxonomy, $append, $old_tt_ids) { //Assuming we only want terms from specific taxonomy //If not simply remove this conditional ...


0

You could achieve this with a little bit of jQuery: Create this file within THEMEFOLDER/js/ called field-clear.js and replace #formID with the ID of the form you would like to reset: //Code runs when an ajax request succeeds jQuery( document ).ajaxSuccess(function( event, xhr, settings ) { //Check ajax action of request that succeeded ...


0

It actually doesn't matter because WooCommerce uses this, to display: $values = wc_get_product_terms( $product->id, $attribute['name'], array( 'fields' => 'names' ) ); However, if you don't set the display to true, you'd have to add this code to your template files. You might have to do other things as well (styling, etc). If you just set the ...


0

I would try to create a wrapping function that can provide values for all those XXX's at runtime. Here's a rough, untested example: function build_and_register_custom_taxonomy($taxonomy_name, $taxonomy_menu_name, $priority) { $definition = function($taxonomy_name) { $labels = array( 'name' => $taxonomy_name, ...


1

If you don't define the field in the array then it defaults to ID. Your options are term_id, name and slug: http://codex.wordpress.org/Class_Reference/WP_Query#Taxonomy_Parameters 'tax_query' => array( array( 'taxonomy' => 'language', 'field' => 'name', 'terms' => get_the_title() ) )


1

Unfortunately WordPress does not support third-level admin menu, so there's no easy way to achieve the result you want. You can only remove these 4 submenu items, add a submenu item instead which will be a link to a custom admin page and display these 4 links within that page (content). Read about following hooks: remove_submenu_page() add_submenu_page() ...


3

To be really honest here, that is a useless parameter when used with custom taxonomies, as custom taxonomies are already registed to a custom post type when they are registered. Using the taxonomies parameter, you are re-registering a custom taxonomy to the custom post type As stated by the codex, the taxonomies parameter is used to register build in ...


0

I don't understand what you want to do. Every taxonomy is independent and the terms can't be shared between them. The only way I know to do a search with 2 parameters: taxonomy A term and taxonomy B term, and pass it to a WP Query along with the custom post type.


0

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', ...


2

I hope I understand your question. You are looking for all terms connected to a single post, but only terms that are children to the adoption-status term To get all the terms from a specific post, you can make use of wp_get_post_terms(). This will return all the terms of a specific taxonomy connected to the post. You will also need to make use of ...


0

As user9279 suggested (albeit a bit hard to understand), go to your Settings -> Permalinks and save them again. This tends to fix issues like this (as well as, for example, a 404 when viewing a newly created custom post type). If this doesn't work, I suggest you look at the order of the registration for the taxonomy / post. The taxonomy should exist before ...


0

The page for any particular term should definitely be an archive page. Check the Template Hierarchy and you will see that wordpress looks for the following templates to display terms taxonomy-(taxonomy)-(term).php taxonomy-(taxonomy).php taxonomy.php archive.php paged.php (maybe) index.php So if you want to create a custom layout, copy your archive.php ...


0

It's the template taxonomy.php, and some variants: http://codex.wordpress.org/Template_Hierarchy#Custom_Taxonomies_display


0

I'm not sure exactly how you want 'term_single' formatted, but you can amend the below as required if it's not quite what you are looking for. I'd also suggest not using the name $posts for your array, as I believe that WP has a global of the same name, so it could cause funkyness that is undesirable. Finally, as you were in The Loop you can use simple ...


0

From the Codex for pre_get_posts: pre_get_posts cannot be used to alter the query for Page requests (page templates) because 'is_page', 'is_singular', 'pagename' and other properties (depending if pretty permalinks are used) are already set by the parse_query() method. See: Query Overview. The recommended way to alter the main query for page requests is ...


1

I recommend you look on the side of Post Meta Boxes. Here's a good guide -> http://www.paulund.co.uk/create-custom-meta-boxes (this is more a comment, but my reputation don't allow me to add a comment)


1

According to the Wordpress Codex page on Template Hierarchy, you create a template file with the name of taxonomy-portfolio_category.php. WordPress will use that to display the archive for that taxonomy. You can also use taxonomy-portfolio_category-{term_name}.php to create templates for specific terms in your taxonomy.


1

As I stated in comments, use pre_get_posts to alter the main query. Never replace the main query with a custom one. Again, from comments Just for starters, on each page load you are running the same query twice, it is slow, double the amount of db calls and pagination has to be tweaked to work almost 100 percent, this just to get the same posts :-) You ...


1

You can do this by recursivly checking each level to see if it exists, with the level above as it parent. While I've never used this code in anger, it is tested and working, though I can't say how efficient it will be, particularly if you have a long hierarchical path. Place this code in functions.php - /** * Return whether or not a given hierarchical ...


0

I think it could be a good idea to create two more hierarchical (category like) taxonomies, called Artists and Albums. This way, you'll be able to query your posts based on taxonomy / term relationships. Basically, what I'm saying is this: Artists -> custom hierarchical taxonomy List item -> custom hierarchical taxonomy Songs -> custom post type Genres -> ...


0

A custom taxonomy makes perfect sense - here's hoping I haven't missed something: $songs = get_posts( array( 'post_type' => 'song', ) ); $index = array(); // Build an album_id => songs index foreach ( $songs as $song ) { if ( $albums = get_the_terms( $song->ID, 'album' ) ) $index[ $albums[0]->term_id ][] = $song; ...


0

$args = array( 'post_type' => 'works', 'posts_per_page' => 40, 'meta_key' => 'wpcf-composition-date', 'orderby' => 'wpcf-composition-date', 'order' => "DESC", 'offset' => $offset, 'tax_query' => array( 'taxonomy' => 'genre', 'field' => 'slug', 'terms' => ...


1

register_taxonomy triggers the action registered_taxonomy immediately after it's registered, which gives you the arguments it was registered with. As long as the taxonomy key doesn't change, you can hook that action, modify the arguments, then re-register it. function wpd_update_taxonomy_args( $taxonomy, $object_type, $args ){ if( 'plugin_tax' == ...


2

You can make use of get_term_children() instead of get_categories() You can try something like this $term = get_queried_object(); $term_id = $term->term_id; $taxonomy_name = $term->taxonomy; $termchildren = get_term_children( $term_id, $taxonomy_name ); echo '<ul>'; foreach ( $termchildren as $child ) { $term = get_term_by( 'id', $child, ...


0

I think i have a function that will do it for you. The usual WP way to highlight the menu item is to add the class "current-menu-item" to the item, then you can style highlighted links with CSS. In this case you want to highlight a taxonomy menu link if we're in a post for that taxonomy, is that right? For example if we're in a post in "CategoryX" we want ...


1

The hierarchical argument when registering a custom post type should be set to false which is also the default setting hierarchical(boolean) (optional) Whether the post type is hierarchical (e.g. page). Allows Parent to be specified. The 'supports' parameter should contain 'page-attributes' to show the parent select box on the editor page.Default: ...


0

get_term_children() should be able to do just that. The example in the link looks good.


-1

I had the same problem even though my taxonomy was registered to Users. Found the answer at Custom user taxonomies in WordPress by Justin Tadlock (see the comments for the post). Add this to your code (replace YOUR_TAXONOMY with the proper name): function fix_user_tax_page( $parent_file = '' ) { global $pagenow; if ( ! empty( $_GET[ 'taxonomy' ] ) ...


0

Your problem is that you are associating a taxonomy and a post type but you don't that associtaion. If you don't want a taxonomy be associated with Posts (standard post type), don't associate them, it is that easy. If you need a taxonomy with no post type associated, set $object_type to null (see codex): function csv_tags_taxonomy() { $labels = array( ...


1

Your "Nutrition plan" post type should use the Repeater Field from ACF: http://www.advancedcustomfields.com/add-ons/repeater-field/ Inside this Repeater Field you have to use "Post Object" filtering only your "Recipes" post type: http://www.advancedcustomfields.com/resources/post-object/


0

I had to do this on a project years ago. Similar answer to djb, just with a bit more details. This will output all of your taxonomy names as an h3, with a bulleted list of each post title linked to their detail page. <?php // Output all Taxonomies names with their respective items $terms = get_terms('member_groups'); foreach( $terms as $term ): ?> ...


-2

Try wp_reset_postdata() I'm pretty sure wp_reset_query() only works on the original global query.


0

It's late, but I found a solution after a pair of hours of search and I'm happy to share it. My solution works for any custom post type, so it won't be needed to specify the custom post type. So, if you are outside the loop, and you need to get the parent category name (or any parameter) of a custom post type, this is the way: $post_type = get_post_type(); ...


0

I see this issue all too often. You should never need to run your own query on an archive page. Not only does it introduce unnecessary load on the server, you confuse the hell out of WordPress as it's no longer aware of how/what exactly you're querying. Instead, tweak the main query to suit your needs and stick to while ( have_posts() ): function ...


0

For your first question: — Where do I have to put the »HTML for the term order metabox«? Take a look at the add_meta_box codex page, the example there shows you how to put a metabox on your posts admin pages. Regarding your second question: — Does the »JavaScript to make the above list sortable and save the order using ajax« has to be enqueued ...


0

try this... replace twentyfourteen_paging_nav(); with global $wp_query; $temp_query = $wp_query; $wp_query = NULL; $wp_query = $loop; twentyfourteen_paging_nav(); $wp_query = NULL; $wp_query = $temp_query;


0

Try to use child_of at your second foreach, see the documentation. child_of (integer) Get all descendents of this term. Default is 0. Note: the difference between child_of and parent is that where parent only gets direct children of the parent term (ie: 1 level down), child_of gets all descendants (as many levels as are available) So in your case ...


0

To see how we can make this work, have a read through the Query Overview Codex page, particularly the What Plugins can Modify section: Modify the query specification, after variable values are saved (request filter or parse_request action; if you want to use conditional tag tests, use the parse_query or pre_get_posts action, as these run after the is_ ...


0

you will probably want to use term_exists http://codex.wordpress.org/Function_Reference/term_exists to check if the term is "valid". Probably worth checking how good is that API with mismatched cases. Another option is to use AJAX to populated your input control base on the user input. I am almost sure there is some jquery plugin for that, and then ...


0

You really should try to avoid using query_posts if at all possible. See When to Use WP Query vs Query Posts vs Get Posts Here is a pass through a loop using WP_Query: $args = array( 'tax_query' => array( array( 'taxonomy' => 'region', 'field' => 'id', 'terms' => $region_id ) ) ); ...


0

Okay thanks for all the helpful comments. It turns out there is no way to do this using WP_QUERY alone. The best way I can think of is to do it is like so: $taxIds = get_terms($options['post-types'][$this->current_post_type->name], array( 'fields' => 'ids', )); $uncategorisedQuery = new WP_Query( ...


1

How about creating those categories Cars, Tvs, Trains and Ships as sub categories of locations? Then you could have a navigation menu containing parent categories i.e Briton, Manchester etc. Once a parent category is navigated to you could have a menu that uses the get_terms() function with the parent argument set to the current location term ID that lists ...


0

I solved this problem by putting everything into the init call and then calling a check on the tax.. to see if it was empty. I'm not convinced that this is the most elegant solution or efficient so maybe someone will correct or confirm what I have found as a solution.


0

First Assumption: That an extra slash was being added for some reason To see what was going on, I wanted to see what was going on in the array. When I print_r() the array I get the following: Array ( [10] => stdClass Object ( [term_id] => 10 [name] => Mozilla [slug] => mozilla [term_group] ...


0

It turns out the issue here is the foreach statement. I changed the loop from foreach ($taxonomies as $taxonomy) { to for ($counter=0; $counter < sizeof($taxonomy); $counter++) { as well as all relivant itirators so.... register_taxonomy( $taxonomy->singular_name, 'book', $tagArgs ); became register_taxonomy( $taxonomy[$counter]->name, ...


1

You can use the parent argument in get_terms() to get direct children of a term. You can use the child_of argument to get all descendents of a term. Something like this. $parent_id = 32; $args = array( 'parent' => $parent_id ); $terms = get_terms( $taxonomy, $args ); print_r( $terms ); If you want to programmatically get parent terms and within ...


0

Untested, but something like this should work. $siteurl = home_url('/'); $tax = 'region'; // slug of taxonomy $terms = get_terms($tax); foreach ($terms as $term) { $id = $term->term_id; $slug = $term->slug; $description = $term->description; $image_url = z_taxonomy_image_url( $id, NULL, TRUE ); $link = "<a ...



Top 50 recent answers are included