New answers tagged

0

You are using WP_query, try to change your loop to: <?php if ($wp_query->have_posts() ): while ($wp_query->have_posts() ) : $wp_query->the_post(); // Do stuff here endwhile; endif; wp_reset_postdata(); ?>


0

It seems to me that you are doing it wrong. You don't need a set of taxonomies but one taxonomy with a set of terms. For example, if a user is located in US, US should be a term that belongs to the country taxonomy, not a taxonomy itself. In the code of your answer you are registering one taxonomy for each country, you will end up with a lot taxonomies ...


0

I got it to work by registering a custom taxonomy... add_action( 'init', 'create_country_tax' ); function create_country_tax() { $userInfo = geoip_detect2_get_info_from_current_ip(); $country = $userInfo->country->isoCode; register_taxonomy($country,'country'); } and then calling taxonomy_exists('US').


2

To answer your first question What is the difference between those functions get_terms() returns an array of terms objects that belongs to a specific taxonomy get_the_terms() returns an array of terms belonging to a post the_terms() displays an HTML formatting string of term names belonging to a post Because you need your terms not hyperlinked and ...


-1

You should use get_the_terms() or get_terms() because the_terms() echo/prints the results and get_the_terms() or get_terms() only get value and save it to variable or memory. An possible example is foreach($posts as $post){ $term= get_the_terms($post->ID, 'category' ); echo 'Category: '.$term; } You may need to use another loop to handle ...


0

Using the wp_dropdown_categories() function there's a parameter you can use called selected which you would assign the selected category ID. You should also standardize the name of your select so it's easier to save: $selected_id = get_post_meta( $post->ID, 'selected_tax', true ); wp_dropdown_categories( array( 'show_option_all' => 'Choose a ...


-1

According to what I understand is : In your taxonomy.php Add this code : $term = get_term_by( 'slug', get_query_var('term'), get_query_var('taxonomy') ); echo '<h2>Showing posts with topic : ' . $term->name .'</h2>'; This will result in showing "Showing post with topic : Cancer" Now for (all posts tagged with cancer already display ...


0

got some idea as your requirement. Check bellow code... $parent=get_queried_object()->term_id; $child = get_categories('child_of='.$parent. '&hide_empty=0&echo=0&taxonomy=custom_taxonomy'); if(count($child)>0){ $i=0; foreach ( $child as $row ) { $i++; echo '<li><a ...


0

Once I have faced problem about this and passed hard times hrs to hrs by pulling hair. I googled and didn't found any specific solution about the topics. I found several talents' article but they weren't satisfying my problems. Actually custom taxonomy archive page pagination is depends on some settings of arguments of related functions. So I am actually ...


0

Below code works well if have multiple terms to show.:- echo get_the_term_list( $post->ID, 'styles', '<ul class="styles"><li>', ',</li><li>', '</li></ul>' );


0

You could try preg_match() if ( preg_match( "/thisfolder/", $imageURL) ) { echo 'your url here'; } See more here: http://php.net/manual/en/function.preg-match.php


0

Simply order by parent... $terms = wp_get_post_terms( $ID , $tax, array( 'orderby' => 'parent', 'order' => 'ASC' ) ); $myparent = $terms[0];


0

You will need to read the taxonomy template article on WordPress.org for that information.


0

I copied your code as-is above, pasted it into the twentysixteen theme, and changed just the post type rewrite slug from review/%brand% to %brand%. This resulted in both the term archive and review posts having your desired URL structure and successfully displaying. Now the bad news is that the rewrite rules generated for the taxonomy and post type stomp ...


0

Easiest way: $rootId = end( get_ancestors( $term_id, 'my_taxonomy' ) ); $root = get_term( $rootId, 'my_taxonomy' ); echo $root->name;


0

If you want to list all the available categories for a custom post type, this snippet might help you. Just use the standard get_categories() function and pass the $args relating to the taxonomy you registered for your CPT. So, if you defined your taxonomy like this: register_taxonomy( 'the_taxonomy_named_in_your_CPT' ); Then you'd show the taxonomy to ...


0

If you are manually registering your custom taxonomy via register_taxonomy then you can pass in arguments to control where the metabox appears. In the example below setting show_ui to false would completely remove the metabox from the edit screen, the quick edit screen, and the admin menu. But if you set show_ui to true you can achieve more nuanced control ...


1

50 is relatively not much, and you should create them on the plugin activation hook. For more then 100 (just pulled the number out of my ass ;) do your own testing on some slow shared hosting) I would create a settings page and initialize the DB from there. The reason is that users do not expect plugin activation to take long and might think that something ...


2

Taxonomy "data" is indeed stored in the database. Taxonomy "definitions" are not. The stuff you put into a call to register_taxonomy is not the data, it's the definition of that data. Stuff you add, like categories or tags, is the data, and yes, it goes in the taxonomy tables like any other taxonomy data. You need to call register_taxonomy every time so ...


1

Note that if you have the post slug, you don't need the additional taxonomy query to find that post, so it makes sense to drop the expensive taxonomy query in core in that case. Otherwise you could try instead the post_name__in parameter: [ 'post_name__in' => [ '<postslug>' ], 'tax_query' => [ [ 'taxonomy' ...


0

Solved i changed for each loop <?php $taxonomies = array( 'urun-kategorileri', ); $args = array( 'orderby' => 'menu-order', 'order' => 'ASC', ); $tax_terms = get_terms($taxonomies, $args); echo '<table class="table table-hover"><tr>'; foreach ...


0

You skip to the else part in after the 4th run of your foreach. Put the $i++ at the end of the loop and your fine. foreach( $tax_terms as $tax_term ) { if( $i <= 4 ) { echo '<td><a href="' . esc_attr( get_term_link( $tax_term, $taxonomy ) ) . '" title="' . sprintf( __( "Profilleri Görüntüle %s" ), $tax_term->name ) . '" ' . '>' ...


0

the_terms() Both the_tags() and the_terms() uses get_the_term_list(), the different is that the_tags() has the default put in for post_tag. Watch them in wp-includes/category-template.php


0

Sorry for a wrong answer. It is posted in other question. About your situation, Heroes seem like Category(Custom Taxonomy) Guides is a custom post (Custom post) About Heroes Type, it can be a subcategory of Heroes or you can create new custom taxonomy for it. In custom post, you just need to embed Heroes Types and Heroes if you have 2 different ...


0

Based on this answer, here is my function to get all your terms in an array : function get_term_ancestors($post_id, $taxonomy){ // Declare the array where we are going to store the terms $ancestors = array(); // start from the current term $parent = array_shift(get_the_terms($post_id,$taxonomy)); // climb up the hierarchy until we reach ...


0

The problem is, there might be 1, 2, 3, 4 or N levels of depth in the subcategories. So, writing the query is possible, but inefficient because to be this flexible, left joins will be required which are not fast.


2

I have found an answer by myself, for those landing here by google: $taxq = array( array( 'taxonomy' => 'story_lng', 'field' => 'id', 'operator' => 'NOT EXISTS', ) ); That results in AND (NOT EXISTS( SELECT 1 FROM wp_term_relationships INNER JOIN wp_term_taxonomy ON ...


1

The only way is to get all the terms and exclude posts which belongs to those terms $taxonomy = 'my_tax'; $terms = get_terms( $taxonomy, ['fields' => 'ids'] // Get only IDS ); // Setup your query args $args = [ 'tax_query' => [ [ 'taxonomy' => $taxonomy, 'terms' => $terms, 'operator' ...


1

Your order of your if/else statement is wrong. You would want to have your complex condition (or most important condition) at the top and the simplest (or least important condition) at the bottom. if/else statements work on the basis that the first condition that hits true will be executed. In your example above, if you have a post that belongs to the ...


1

Add a autocomplete 'select' catch to your first autocomplete field. Use this to get the chosen value from the autocomplete. Use an Ajax call to obtain your next autocomplete source based on the selected value and apply the new source to the next autocomplete field. jQuery( "#cns-make" ).autocomplete({ source: availableTags, select: function (event, ...


2

The third argument for term_exists() is an integer, not an array. Parameters $term (integer|string) (required) The term to check Default: None $taxonomy (string) (optional) The taxonomy name to use Default: '' $parent (integer) (optional) $parent ID of parent term under which to confine the exists search Default: ...


0

A much shorter solution, just add this before foreach: usort($terms, function($a, $b) { return get_field('issue_date', $a) - get_field('issue_date', $b); });


1

Hi the autocomplete expects source to be array, URL string and function return. Even if you give JSON then it should have label and value. Which is not present here as you are simply output the get_terms with all fields. So what I would suggest is just return the name of categories. Changing the fields from all to names will work well. <?php $args = ...



Top 50 recent answers are included