New answers tagged

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

Use get_terms and specify name and parent. $name = 'Flowers'; $parent_id = 42; $args = array( 'name' => $name, 'parent' => $parent_id ); $terms = get_terms( 'category', $args );


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>' );


11

Object cache everywhere WordPress tries to reduce the number of database queries as much as possible. For example, anytime you get a meta field or a taxonomy field, before querying the database, WordPress looks if that that was already queried and stored in cache, and returns it from there instead of querying the database. The "cache job" is done via ...


3

The main point of interest here is the update_post_caches function. It is called after WP_Query got all the posts from the DB. Usually, the reason you want the posts in the first place is to display them which usually means to display the terms and something based on the metadata, therefor WP_Query will also by default query the DB for the meta and term data ...


0

I am not sure how you are activating theme on Network but here I am considering a case of installing fresh theme on a existing Network. Activating theme on any single site will insert the term for every site in Network but yes of course taxonomy registration code should be there already. Consider this example function after_switch_theme_callback() { ...


2

This should be possible with the tax_query parameters for WP_Query. The query is either for posts where any term NOT EXISTS, OR, for any posts where the term IDs are IN the provided array. 'tax_query' => array( 'relation' => 'OR', array( 'taxonomy' => 'group', 'operator' => 'NOT EXISTS', ), array( ...


0

If you don't want to mess around with Wordpress nonsense of it ignoring taxonomies which clearly exist in the database, whether they be registered or not, you can just use a replacement function like this to grab the taxonomy at any time. function custom_get_terms($term) { global $wpdb; $out = array(); $a = ...


0

Posts are things Taxonomies and terms are types or classifications of things E.g. I could have a post type animal, with animals such as "Betsy", "Rover", and "Mittens". I can then have a taxonomy called species, that contains terms such as cat, dog, budgie. I can then assign the "Mittens" post to the cat term in the species taxonomy. The important part ...


0

The following code will generate drop-down with terms, but also can generate any other element/structure by editing the $outputTemplate variable, and editing str_replace lines: function get_terms_hierarchical($terms, $output = '', $parent_id = 0, $level = 0) { //Out Template $outputTemplate = '<option ...


1

Ok, I just stumbled upon the answer buried deep in the github issues page: https://github.com/WP-API/WP-API/issues/1403 The answer is: the reason is that the terms / meta etc are different objects, and in typical REST design going a GET on a single resource, will give you that resource, not that resource and a bunch of other ones too. However, ...


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); });


0

i back @Charles answer, along with that another workaround is to create new object of WP_Query class, and use that object's loop instead of default loop, Dont forget to use $wp_query->query_vars['taxonomy_name'] to get the current taxanomy and load it into WP_Query's object parameters. with that you can use posts_per_page. more details here


1

Maybe a very quick and (simplified)dirty way I show here, but would this function not solve it without the need to make changes for/in the templates? (Yes I know I also make queries in my templates but wanted to help out before leaving office) function wpse214084_max_post_queries( $query ) { if(is_tax('genre')){ // change genre into your taxonomy or ...



Top 50 recent answers are included