Tag Info

New answers tagged

0

You can get all the terms in a custom taxonomy using the following code: $terms = get_terms( 'development-category' ); if ( ! empty( $terms ) && ! is_wp_error( $terms ) ){ foreach ( $terms as $term ) { $loop = new WP_Query( array( 'development-category' => $term->slug, 'post_type' => 'developments' ) ); ?> .... ...


0

with enough effort almost anything is possible, but it might not be easy. what you basically want is for each user to have its own taxonomy, but merge them all when displaying it on the front end. The easiest path is probably to go multisite with a site per author and aggregate things on the front end.


0

You can use get_queried_object to return the full queried term object on a taxonomy archive page. $term = get_queried_object(); if( 0 === $term->parent ){ // term is top level } else { // term has parent }


1

I learned from the comments by @Pieter Goosen and @Ignat.B, and @Pieter Goosen's answer here, that I need to register the taxonomy on plugin activation, and insert the term. Then I need to hook the taxonomy registration code to the init action hook as suggested by the codex. This will ensure that when I insert the term on plugin activation, I have the ...


0

Isn't what you are trying to achieve the point of the rewrite slug? e.g. if you have a news category as press and another as event then simply changing register_taxonomy('news_category', 'stfp_news', array( 'hierarchical' => true, 'show_admin_column' => true, 'label' => __('Categories'), 'show_ui' => true, 'query_var' => false, 'rewrite' ...


0

To get the attached term IDs, use get_the_terms() and wp_list_pluck(): if ( $terms = get_the_terms( $post, 'director' ) ) { $term_ids = wp_list_pluck( $terms, 'term_id' ); }


0

when registering the post type , try 'exclude_from_search' => false,


2

register_activation_hook is one-time only activation hook. It can be used for database structure creation, as example, that needs to fire only on plugin activation trigger. In order to set a custom taxonomy you need a hook that will fire not just once, but per every WordPress load. Such as init. Use add_action( 'init', 'YOUR_CALLBACK' ); to achieve that


0

Place this function in your functions.php: function adjacent_post_by_category( $category, $direction, $content ) { // Info $postIDs = array(); $currentPost = get_the_ID(); // Get posts based on category $postArray = get_posts( array( 'category' => $category, 'orderby'=>'post_date', 'order'=> 'DESC' ...


0

I think, the problem is that you just put filtered query in $query variable but did not set it in the main query i.e. $query->set() See if this works in your code - $query->set( 'tax_query', $taxquery ); instead of $query = new WP_Query( $taxquery );


1

It's as easy as: function wpse_199523_save_imdb_terms( $post_id ) { if ( ! $imdb = get_field( 'imdb_id', $post_id ) ) return; if ( ! $data = imdb_connector_get_movie( $imdb ) ) return; if ( ! empty( $data['actors'] ) ) wp_set_object_terms( $post_id, $data['actors'], 'actors' ); if ( ! empty( $data['director'] ) ) ...


1

I was able to solve this by defining a rewrite rule: function rewrite_rules($rules) { $newRules = array(); $newRules['states/(.+)/(.+?)$'] = 'index.php?district=$matches[2]'; return array_merge($newRules, $rules); } add_filter('rewrite_rules_array', __NAMESPACE__ . '\\rewrite_rules');


0

$_POST['tax_input[genres]'] should be $_POST['tax_input']['genres']


1

Typically when you want to create an extra representation or variation it implies extending URL a bit and treating that case differently. The easiest way in WP for that are rewrite endpoints. However the ease is relative you still need to handle with code the changes in a query and how to produce output. WP doesn't have an easy native concept of multiple ...


0

I've managed to figure this out myself, so if anyone out there needs some help please try the following... Using the get_terms rather than trying to query it directly. <?php $terms = get_terms('custom-tax-name', array('hierarchical' => false)); foreach ($terms as $term) { $term_link = ...


0

Use the Co-Authors Plus to assign the authors and the post will show automatically on both author pages. I've used it and works pretty well.


0

You can use the template functions given by Co-Authors Plus plugin such as, coauthors_posts_links() - Co-Authors Plus equivalent of the_author_posts_link() template tag. coauthors() - Co-Authors Plus equivalent of the_author() template tag. Please refer to their documentation


1

Use tis plugin https://wordpress.org/plugins/acategory-dropdown-list/ It may be help you


0

First get the posts that have the taxonomy you need $posts = get_posts('resource type' => 'archive') Then loop the results and use this function wp_get_post_terms($post_id) I think you got it figured out how to display your results


0

Solved the issue by passing the term_name as a parameter to the callback function to the filter. function bn_term_title( $term_name ) { $term_types = get_term_by( 'name', $term_name, 'tax_1' ); if( $term_types->taxonomy === 'tax_1' ) { if( get_locale() === 'bn_BD' ) return get_term_meta( $term_types->term_id, 'tax1_bn' ); ...


0

If you just want to list them you can use the get_terms function: $terms = get_terms( 'my_taxonomy' ); if ( ! empty( $terms ) && ! is_wp_error( $terms ) ){ echo '<ul>'; foreach ( $terms as $term ) { echo '<li>' . $term->name . '</li>'; } echo '</ul>'; } Read the codex, it has a lot of examples: ...


1

First option: Creating custom taxonomy and then save domain as terms. Basically "taxonomy" is a grouping mechanism. In your requiremnt there would not be too many CPTs are of same taxonomy. For Taxonomy, you have to maintain 3 tables, wp_terms, wp_term_taxonomy and wp_term_relationships. So, while creating a NEWS (your CPT), you will fire queries on these ...


2

You are fetching all the terms of your taxonomy, Use this instead : $terms = wp_get_post_terms(get_the_ID(), 'city-type'); if ( ! empty( $terms ) && ! is_wp_error( $terms ) ){ foreach ( $terms as $term ) { echo '<span>' . $term->name . '</span>'; } } Note : First argument to the function is id of the ...


1

The first issue as I see it is that you are using the_terms function. If you actually look in the source code you will see that after a couple of other function calls the whole thing fails because eventually the function get_the_terms is called which checks if the ID you are passing is a valid post. Sometimes this might work though if the user_id might ...


0

Each term object has a parent attribute which is set to 0 in case it's a parent root term or the ID of the parent in case it is a child term. So, if you have only one level of child terms then you can check for that attribute to not be equal to 0 in which case the term has a parent. $object_terms = wp_get_object_terms( $post->ID, 'types', array( 'fields' ...


1

Strictly regarding your question: get_object_taxonomies( 'user' ); since user is the $object_type that it is used when the author registers the taxonomy.


0

Each taxonomy object will have _builtin set to 1 for native taxonomies, so check $taxonomy->_builtin in your foreach loop first before fetching the terms.


0

Have just tweaked your code to achieve what you need. See, if this works for you - $taxonomyName = "age"; $parent_terms = get_terms($taxonomyName, array('parent' => 0, 'orderby' => 'slug', 'hide_empty' => false)); echo '<ul>'; foreach ($parent_terms as $pterm) { $terms = get_terms($taxonomyName, array('parent' => $pterm->term_id, ...


0

There is no simple way to get this from scouring. And everyone who answers everywhere thinks you want to link to a TERM in the TAXONOMY... While you're looking to get a link to the TAXONOMY archive... For which I have found absolutely nothing. Basically, like many people, you want a get_taxonomy_archive_link method. Except, for one reason or another, it ...


1

Personally I would not recommend breaking the taxonomy archives - what if someone wants to browse all posts tagged "ferrari"? You're better off using the page URL in the first place: if ( $tags = get_the_terms( $post, 'vehicle' ) ) { foreach ( $tags as $tag ) { if ( $_page = get_page_by_path( "cars/$tag->slug" ) ) printf( '<a ...


2

There is no tax_query parameter for the WP_User_Query class. Since you've tagged the question with user-meta I can only assume you store the ID (or even the term name itself?) of a particular shop-category term as a user meta entry. In this case you would need something like this: // The 'WP_User_Query' arguments array $args = array( 'role' ...


1

As I have stated in comments, this will take some work. In short, you will need the following: Get all the terms from the style taxonomy. Here we would only want the term ids Get the current tax_query from the colour taxonomy. Use each term from the style taxonomy and create a new tax_query to get posts from the current page's term and the term being ...


0

Ok, I think I have found a way of doing this. Although I must say I haven't tested it out yet and it's probably not the best way. So happy to see any other solutions. What I have done is created a meta box in my custom post with a radio button that has options "featured" and "not featured". I set the three custom posts of each group I want to show and then ...


0

I solved it: Just in case anybody ever has any trouble querying a post with the same term of a Taxonomy in another Post Type. I'll post my answer below because I finally solved it on my own. <?php $terms = get_the_terms( $post->ID, 'supplier-tax'); foreach ( $terms as $term ) { $termID[] = $term->term_id; } $the_query = new WP_Query( array( ...


0

Not sure why your object is returning the non-object notice, but you can set the output of get_term_by to OBJECT, ARRAY_A, or ARRAY_N - You'll want to use ARRAY_A and then access the term ID via $term['term_id'].


0

The 'child_of' argument lets you select subcategories from a parent category, and a you can get the current taxonomy id to pass as the value: <?php $category_id = get_queried_object_id(); $args = array( 'hide_empty'=>1, 'depth'=>1, 'hierarchical'=> 0, 'show_count'=> 1, 'taxonomy'=> 'portfolio-types', 'child_of' ...


1

What you would do, is have your default single-article.php. This will get called by default because of the WP permalinks and templating system. At the top of your single-article.php do the following before your get_header() call: <?php $language = get_the_terms( get_the_ID(), 'language' ); if ( ! is_wp_error( $language) && $language && ...



Top 50 recent answers are included