Tag Info

New answers tagged

-2

use this code for solving your problem. <?php $args = array( 'orderby' =>'name', 'texonomy' =>'category', 'child_of' =>0, 'parent' =>0 ); $cats = get_categories($args); foreach ($cats as $cat) { echo $cat->name; $arg = array('orderby' => 'name', ...


-2

i thinks this function are used for get term link. get_term_link($terms,texonomy_name); this function is perfectly work.


1

I do not know how ACF works or how its data is stored, but in general, I would just use usort() to sort the returned array of terms via the ACF value of cognome_nome. Note that array_push is a bit expensive to use, so try to avoid that ;-) As I stated in comments, your code does not make much sense to me. You have two separate foreach loops, which is fine, ...


0

EDIT: On a post page, the categories are already seen in hierarchical manner but with checkboxes. So, I have assumed that you have to show list of all the categories/subcategories somewhere in the admin panel in following format. Category 1 Sub-Category 1.1 Sub-Category 1.2 Category 2 So, presentation is upto you, I have just given logic to pull ...


1

As of PHP 5.4, you can directly dereference an array, so to get the first term, you can simply do. $first_term = get_the_terms( $post->ID, 'TAXONOMY_NAME' )[0]; var_dump( $first_term ); If you need a specific property (say the term name) of the first term, you can do the following $first_term_name = get_the_terms( $post->ID, 'TAXONOMY_NAME' ...


0

how about directly access the key of object? $terms = get_the_terms( $post->ID, 'sitecat' ); $first_term = $terms[0]; so you can access the object. echo $first_term->name;


1

Your best option will be to get an array of term ids by using get_terms which belongs to the authors taxonomy and then using that as your array of terms in your tax_query The following requires PHP5.4+ $term_ids = get_terms( 'authors', ['fields' => 'ids'] ); // Only get term ids $args = [ 'tax_query' => [ [ 'taxonomy' => ...


0

use some thing like this $queried_object = get_queried_object(); $term_id = $queried_object->term_id; Most probably $term_id should give the id of the taxonomy term of the current page, try echo $term_id; If it doesn't then try using var_dump() like echo "<pre>";var_dump( $queried_object )echo "</pre>"; Analyse the output , and use it ...


0

This may help you: <?php //first get the current term $current_term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) ); //then set the args for wp_list_categories $args = array( 'child_of' => $current_term->term_id, 'taxonomy' => $current_term->taxonomy, 'hide_empty' => 0, 'hierarchical' => ...


2

You can try the MySQL function SUBSTRING_INDEX() within the get_terms_orderby filter: /** * Order by the last word in the term name * @link http://wordpress.stackexchange.com/a/195039/26350 */ add_filter( 'get_terms_orderby', function( $orderby, $args ) { if( isset( $args['orderby'] ) && 'wpse_last_word' === $args['orderby'] ) ...


0

Improved! Thks @Sisir Now, you can define more than one post type and term. You can define Allowed Post Types in ($arrayPostTypeAllowed) array, and Allowed Terms in ($arrayTermsAllowed) array. add_action('save_post', 'assign_parent_terms', 10, 2); function assign_parent_terms($post_id, $post){ $arrayPostTypeAllowed = array('product'); ...


0

If your URL structure is valid and correct, all you need then is the default loop. The main query runs on each and every page request, and the parameters passed to WP_Query ( yes, the main query also uses WP_Query) is determined by the URL and rewrite rules for that specific page. If your URL structure is a valid structure and matches a true page request ...


0

There's at least 3 options: You could take the code for the native recent posts widget and modify it in your child theme to work with your custom taxonomy. You could create a new WP_Query using the tax parameters. Or you could use a filter widget_posts_args to modify the default output of the native recent posts widget so it outputs your custom taxonomy. ...


0

The simplest solution: echo get_the_category_list( ', ' ); Following your way: Change your $args like so: $args = array( 'template' => '%2$l', 'term_template' => '%2$s', ); And then, add this to your functions.php file (this will affect all %l markers!); add_filter( 'wp_sprintf_l', function($templates) { // ...


0

The category parameters does not work with custom taxonomies. You need to use a tax_query instead. In your current code, replace (which is in any case also wrongly used, category_name takes the slug, not name) 'category_name' => $category->name with 'post_type' => 'case-studies', 'tax_query' => array( array( 'taxonomy' => $tax ...


0

This code display all posts of all categories of location taxonomy for custom post type testaismgallery. $args = array( 'number' => $number, 'hide_empty' => $hide_empty, 'include' => $ids ); $custom_categories = get_terms( 'location', $args ); foreach ( $custom_categories as $catterm){ $arg = ...


1

The simple and quickest solution is showing categories list by using sitemap plugin with short-code. For example this plugin WP Sitemap Page. Install it and place shortcode on page. Second option is create page template for category list. Using wp_list_categories() Thanks



Top 50 recent answers are included