New answers tagged

0

Try this code after the $bio = wp_insert_post( $my_bio_post ); line: $terms = isset($_POST['my_pet']) ? array_filter($_POST['my_pet']) : 0; if ($terms && $bio) wp_set_object_terms($bio, $terms, 'Cats'); See wp_set_object_terms() for more info and make sure the Cats taxonomy and the terms in your checkboxes is already available.


2

WordPress will cache all terms for taxonomies attached to all post types in the query result set by default - well, so long as you haven't set either cache_results or update_post_term_cache to false (codex). So calling get_the_terms etc. within the loop will not hit the database. However, wp_get_object_terms will hit the database as it by-passes WordPress' ...


0

Just change 'fields' => 'name' to 'fields' => 'names' If you look at the examples in wordpress documentation you can see you should use plural(names, slugs, ids for fields): https://codex.wordpress.org/Function_Reference/wp_get_post_terms#Examples


0

If you just need IDs, get_ancestors will return an array of parents for any type of object: $term_id = 21; $ancestors = get_ancestors( $term_id, 'location' );


1

Use get_term_children() $term_id = 2; // use get_queried_object()->term_id; to get the current term id $taxonomy_name = 'mypages'; // use use get_queried_object()->taxonomy; to get the current taxonomy name $countchildren = count (get_term_children( $term_id, $taxonomy_name )); echo $countchildren;


0

Here's the fix. All the attachment info is now being called inside the php using wp_prepare_attachment_for_js and the info will load for each image in the loop, to display in the photo gallery. It works now. <?php $the_query = new WP_Query(array( 'post_type' => 'attachment', 'post_status' => 'inherit', 'category_name' => 'arch' ...


0

I had a answer in development then I read what you were looking for some more. I will need more info before I can help. Is a reviewer/speaker a custom post type or a user? Is this relationship only going to be displayed on the article. Or will you also be displaying it on the Guest Authors/Speakers page as well?


0

OK. There where multiple issues here; wp_terms, wp_termmeta and wp_term_taxonomy all had their ID's set not to AUTO_INCREMENT. Changing these and removing the 0 values from each table seems to have resolved this - very odd though. Big thanks to @N00b for helping!


0

There's a slight catch to using bainternet's Tax Meta Class: the way you save and retrieve data changes depending on your Wordpress version. If you are using the latest version of WordPress then use get_term_meta instead of get_tax_meta. https://github.com/bainternet/Tax-Meta-Class/issues/115#issuecomment-170365995 I believe the exact ...


1

You cannot query users by taxonomy. You will need to rethink your system. What would I do? Keep the taxonomies but use these only to output choosable values - wp_dropdown_categories() Save the selected value AS user meta, NOT AS taxonomies - update_user_meta() Now you can query users by that value - WP_User_Query() Example: This code would go to the ...


0

Problem was that I had broken the permalink structure for the CPT with the following filter: function classes_permalink_structure($post_link, $post, $permalink, $sample) { if (strpos($permalink, '%classes_class_type%') === FALSE) return $permalink; // Get post $post = get_post($post_id); ...



Top 50 recent answers are included