Tag Info

New answers tagged

0

Took some time, figured it out. Just a matter of working with the array of data from the custom taxonomy used in the advanced custom field: <div class="container"> <?php $rows = get_field('asset'); if($rows) { foreach($rows as $row) { echo '<div class="mix img ' . ...


0

Looking at the code as is, it appears that after you finish your foreach, $term will be set to the last object in the $terms array. Nothing further happens with $term, so when you use $term->name in your $rows foreach, the value will always be the same.


0

If I understand you correctly, you need to show all posts from a term when a term's page is being displayed. Before I answer the real question, there are a few points I would like to highlight since you are new to Wordpress Never use hyphens (-) to separate names in custom post type names and custom taxonomy names. They are extremely troublesome later, ...


2

You cannot use the same object of WP_Query twice. Therefore you need to create another one with a tax_query parameter to fetch posts which are not assigned to any term. //fetch all reviews which have no assigned term in 'review-product' $taxonomy = 'review-product'; $post_type = 'reviews'; $args = array( 'post_type' => $post_type, 'tax_query' ...


1

Try this: function custom_set_term_to_post(){ $args = array( 'post_type' => 'post', ); $all_posts = get_posts(); foreach ($all_posts as $key => $post) { $tag_name = 'post_tag'; // required tag name $term_list = wp_get_post_terms($post->ID, $tag_name, array("fields" => "ids")); if ...


0

I have found a solution. Thanks to @Tarukus as his answer was helpful. Again, my goal was to display terms (not posts) from my custom taxonomy via an on/off switch. To do this, I used Advanced Custom Fields and created a "Select" field with two values (on/off). Once this field was applied to my taxonomy I could select a value for each term. The default value ...


1

/** * Get the author post count for a tax query. * * @link http://wordpress.stackexchange.com/q/159160/1685 * * @param array $tax_query * @return int */ function wpse_159160_get_author_posts_by_tax( $tax_query ) { global $wpdb; $where = get_posts_by_author_sql( 'post', true, get_post()->post_author ); $tax_query = new ...


0

Hy, From what I understand you want a filter to display posts that belong to a specific list of terms. As default you display all posts making all terms enabled. In order to disable a term from being displayed you need to exclude it from the loop. <?php // we get all the terms of the taxonomy $terms = get_terms('mytaxonomy'); /* ...


0

In this specific case, it seems the multiple taxonomies have a clear hierarchical relationship. Rather than a unique taxonomy for building 1, building 2, etc., these can all be located in a single "Buildings" taxonomy that is hierarchical like this: Buildings Taxonomy: Building 1 Floor 1 Floor 2 Floor 3 Building 2 Floor 1 etc. This means that ...


3

First: don't use query_post for secondary loops. It alter the main query and you can end up with wire results. Instead use a new WP_Query instance. See this question for detail info. Now with your proble. You are using the "cat" parameter and that is for "category" taxonomy, not for your custom taxonomy. You should use the tax_query parameter instead: ...


3

You have a few flaws in your code that are causing this failure First of all, and most important of all, never (my emphasis) use query_posts to construct a custom query. Note: This function isn't meant to be used by plugins or themes. As explained later, there are better, more performant options to alter the main query. query_posts() is overly ...


2

The correct way to register a taxonomy is to wait for the action registered_post_type, because that’s the only way to know that your post type actually exists. This action is fired when a post type was registered. Core post types are registered twice for reasons. You have to wait for the second call, because the rewrite object is not available earlier. If ...


0

From the register_taxonomy() codex page: Better be safe than sorry when registering custom taxonomies for custom post types. Use register_taxonomy_for_object_type() right after the function to interconnect them. Else you could run into minetraps where the post type isn't attached inside filter callback that run during parse_request or pre_get_posts. ...


0

Try this add_action( 'init', 'tag_synchro', 10 ); It might be the case that, when you set priority to 0 , your callback does not get called.


0

You are looking for function get_term_link. Example $my_term_link = get_term_link($cat_lists); Here $cat_lists is term object. Official Documentation


1

This might not answer your question, but you have a few issues with your code Do not use uppercase letters in function names, taxonomy names and custom post type names. Only use lowercase letters. Separate names with a underscore (_). Also, just a tip, never start these names with letters, or use a hyphen (-) to separate names Never use ...


1

When you are on a taxonomy page, you can get the parent from the term being displayed by using the following code with get_queried_object. See get_terms for the objects that are returned $queried_object = get_queried_object('term'); $term = $queried_object->parent; To get the taxonomy, you can simply just add $tax = $queried_object->taxonomy; ...


0

Make the following modifications, I hope it will do the job function AppManager_custom_taxonomy() { $labels = array( 'name' => _x( 'App Categories', 'taxonomy general name' ), 'singular_name' => _x( 'App Category', 'taxonomy singular name' ), 'search_items' => __( 'Search App Categories' ), 'all_items' ...


0

To just do it in a front-end way, you can remove the delete action using a filter, and (as there doesn't appear to be a filter to do this) disable & hide the checkbox using jquery: define( 'PROTECTED_TERM_ID', 2 ); define( 'CUSTOM_TAX', 'genres' ); function wpse158784_custom_tax_row_actions( $actions, $tag ) { if ( $tag->term_id == ...


2

Update Indeed, there is a way to define one term per taxonomy as default term which makes it non-deletable from the admin GUI. WP_Terms_List_Table looks for an option get_option( 'default_' . $this->screen->taxonomy ). So if you have a custom Taxonomy called genre, you have to set an option default_genre with the term-id of the term you want to ...


0

I'm not sure if you can stop a term from being removed, but you can make sure it always exists. Just throw this in your functions.php (or plugin): if ( !term_exists('locked-term', 'category' ) ) wp_insert_term('Locked Term', 'category', array('slug' => 'locked-term')); So, to be clear, technically they can remove the term, but the next time the site ...


0

The problem is that you are passing a comma separated list of terms, not an array of term. For example, if you enter 'army,navy,airforce' in the custom field: $related = array ( get_post_meta($post->ID, 'related_categories', true) ); //$related = array('army,navy,airforce'); //What you need is //$related = array('army','navy,'airforce'); You need to ...


0

wp_list_categories() is an odd function in that it's uniquely useful in certain situations with custom taxonomies but it was originally written before they even existed. (It was introduced in 2.1 and the taxonomy attribute was added in 3.0 (source).) What you're seeing is a known issue with an associated bug report (filed two years ago, last activity four ...


0

I haven't tested this extensively but it does work on both Publish and Update. When a post is Published or Updated it checks if a parent is set, grabs the parent to get all the parents taxonomies, then loops through and sets the children terms as the parents terms taxonomy by taxonomy. /** Set Child Terms to Parent Terms **/ function set_parent_terms( ...


1

I'm not exactly sure where you want your clearfix to come in, but you should be able to do something like this: <div class="row"> <?php $libargs=array( 'orderby' => 'name', 'order' => 'ASC', 'hide_empty' => 0, 'exclude' => array(16, 20, 22,25, 27, 28, ...


2

You might be able to accomplish this using Advanced Custom Fields: http://www.advancedcustomfields.com/resources/taxonomy/ Field groups, like the taxonomy field, can be assigned to templates. Editing the taxonomy archive page, the user would see checkboxes (or radio buttons, or a select menu) for the taxonomy terms. In the corresponding "taxonomy archive" ...


0

You can do this with the current object with get_queried_object() $posts = get_queried_object(); echo $posts->count; Otherwise you may unnecessarily run a second query, right?


0

I believe the behavior you're hoping for is not part of WordPress core. The last time I needed this, I adapted a couple functions out of the Post Type Archive Link plugin used for improved post type highlighting. To use it, just add the menu items the normal way and put these functions in a plugin or theme. // Get menus to play nicely with the submenu ...


2

You can use get_term_by() for this <?php $term_id = array_pop(get_sub_field('sector_selector')); $catinfo = get_term_by( 'id', $term_id, 'name_of_the_taxonomy' ); print $catinfo->slug;


0

You have serious issues with your naming conventions, structure of your functions, invalid usage of reserved names and wrong values passed to parameters First, naming coventions. Function names should be lowercase letters, should not start with a letter and words should be divided by underscores (_). The same goes for custom post type and taxonomy names. ...


1

has_term must be used inside the loop. If you use it outside the loop you have to pass the post ID or post object you want to check. In the single.php file put your code inside the loop to check the current post: <?php get_header(); while(have_post) { the_post(); ?> <div class="non-home-parallax product-listing-parallax" style=" ...


0

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: ...


0

I think you need to include the discipline variable in the custom permalink structure /%discipline%/%postname%


0

First get all the posts with the tag "LA Lakers". Then add "LA Lakers" as the new taxonomy terms for those posts. //Get all post with the tag LA Lakers $query = new WP_Query( 'tag=LA Lakers' ); //Loop through all the posts while( $query->have_posts() ) { $query->the_post(); //Set "LA Lakers" as taxonomy terms for these posts ...


1

Your code is correct, well almost correct. On first view, I must confess, I missed it too. You have two syntax errors in your code. If you look closely, 'parent ' and 'parent' is not the same. You should not leave blank spaces between single quotes (') and arguments. Also, you don't need to add a , after your last argument. This should work $cat_args = ...


0

get_terms and get_posts return arrays not objects. Try this: <?php $disciplines = get_terms('disciplines'); foreach($disciplines as $discipline) { echo '<li><a href="#">' . $discipline['name'] . '</a></li>'; $post_args = array( 'post_type' => 'users', 'disciplines' => $discipline['term_id']); $posts = ...


0

Thanks Tomas, Here is solution for someone, who had same problem: $citys = get_the_terms( $post->ID, 'city' ); if ( $citys && ! is_wp_error( $citys ) ) : $city_link = array(); foreach ( $citys as $city ) { $city_link[] = '<a href="city/'.$city->slug.'">' . $city->name . '</a>'; } ...


0

<?php get_the_terms( get_the_ID(), 'city' ); ?> You can learn more about this function here.


1

You could just include it in your functions.php: if ( ! is_admin() ) { include ABSPATH . 'wp-admin/includes/template.php'; }


1

You almost had it with $_GET['zap_audience'], but not quite, since it isn't passed in as a GET variable. It is however a query variable, so try these: $post_type = get_query_var( 'post_type' ); $audience = get_query_var( 'zap_audience' ); $city = get_query_var( 'zap_cities' ); Also +1 for prefixing your taxonomy types with zap_


0

Why don't you use "parent" parameter of get_terms $page = ( get_query_var('paged') ) ? get_query_var( 'paged' ) : 1; // number of tags to show per-page $per_page = 24; $offset = ( $page-1 ) * $per_page; $args = array( 'number' => $per_page, 'offset' => $offset, 'hide_empty' => 1,'hierarchical ' => true, 'parent'=>'term_id of Indigenous ...


0

The way I read you question is that you need 12 posts per page in this taxonomy regardless of the current term been displayed. This can be easily done with pre_get_posts. You should never change the main query for a custom query on archive pages. Have a read on this answer I've recently done on this subject. Use the is_tax() conditional to target the ...


0

What you are describing is loosely related to "faceted search", but you aren't quite searching. :) In a nutshell you would need to: Communicate information about "selected" taxonomy to the page, this might be done with GET query or rewrite endpoint Generate links (or whatever interface you have) accordingly Adjust main query (!) of the page via ...


0

After way too much Googling, here's a fix :) add_filter('wp_terms_checklist_args', function ($args) { $args['checked_ontop'] = false; return $args; });


0

It makes sense that each attribute should be a taxonomy - eg roots, leaves, seeds - but you don't need a separate taxonomy for months. Instead, the months should be the terms of these taxonomies. The second argument to register_taxonomy in each case should be the name of your custom post type. This will mean you'll get a box for each taxonomy on the 'Edit ...


0

You could hijack the $query just before fetching the posts. function wpdev_156674_pre_get_posts( $query ) { if ( $query->is_main_query() && $query->is_tax( 'region' ) ) { // Manipulate $query here, for instance like so $query->set( 'orderby', 'meta_value_num' ); $query->set( 'meta_key', ...


0

If the option is auto loading (and in pippin's code they are) then there isn't any difference except for coding style as all auto loadable options are fetched together in one query in init time and cached in the memory and at this point get_option is not more then a wrapper around accessing a php array. If you decide to use not auto loading option it ...


0

There is a plugin for that http://wordpress.org/extend/plugins/taxonomy-metadata/ OR Adding custom meta fields to a taxonomy requires three separate functions: one to add the field to the Add New page; one to add the field to the Edit Term page; and one to save the values of the custom field from both pages. You can also do this by code yourself like ...



Top 50 recent answers are included