List the category tree of all the product_cat categories
List the category tree of all the product_cat categories
List the category tree of all the product_cat categories
In the end I added a quick check with taxonomy_exists($slug) and if it doesn’t exist before adding the terms I use register_taxonomy($taxonomySlug, ‘product’) This seems to have allowed creation of all terms in one go.
List posts grouped by children of a custom taxonomy
You can try this: /** * List the taxonomies and terms for a given post * * @param int $post_id * @return string */ function get_the_current_tax_terms_wpse( $post_id ) { // get taxonomies for the current post type $taxonomies = get_object_taxonomies( get_post_type( $post_id ) ); $html = “”; foreach ( (array) $taxonomies as $taxonomy) { // … Read more
If I understood you correctly, you are looking for get_the_terms(), which.. Retrieves the terms of the taxonomy that are attached to the post. You could for example have helper functions like these, // functions.php function my_sports_post_terms( int $post_id ) : array { $taxonomies = [‘basketball’, ‘volleyball’, ‘baseball’]; $terms = []; foreach ($taxonomies as $taxonomy) { … Read more
Firstly, this isn’t a WordPress error. It’s a PHP error. WordPress is not going to return type errors. That all happens and the language level. If you used the same values outside of WordPress you’d get the same error. Regarding your specific issue, keep in mind that get_terms() will return a WP_Error object if the … Read more
Most sensible here is probably just a custom query global $wpdb; $sql_find_meta = “SELECT post_id FROM database_name_here.wp_postmeta WHERE meta_key = ‘my_special_value’ AND meta_value > ”;”; // > ” == not null, whitespace or blank $posts_with_meta_key = $wpdb->get_col( $sql_find_meta ); foreach ( $posts_with_meta_key as etc….. You can repeat this for wp_termmeta and term_id
This issue shouldn’t happen if you’re using the classic editor, however, if you’re using the block/Gutenberg editor which uses the REST API, then that issue can be fixed by using the wp_after_insert_post hook instead. Excerpt from https://make.wordpress.org/core/2020/11/20/new-action-wp_after_insert_post-in-wordpress-5-6/: The new action wp_after_insert_post has been added to WordPress 5.6 to allow theme and plugin developers to run … Read more
I don’t think there’s a way you can setup the arguments such that you can get all children of a term and that term in one call, so you’ll probably just have to tack on the parent as a separate call. Using get_terms for the children, then get_term. $parent_id = 100; // set as appropriate … Read more
This isn’t possible, you can’t safely/reliably query the internals of meta value strings that way, and you can’t use it as a form of indirection: You can query for substrings or for whole values, but you can’t query the internals of serialised PHP values without major performance reliability and consistency issues but if you could, … Read more