New answers tagged

1

If you want to change the order of an already existing query, you shouldn't create a new WP_Query object but instead use pre_get_posts to alter the existing query, which prevents multiple queries running unnecessarily. From the pre_get_posts docs: This hook is called after the query variable object is created, but before the actual query is run. ...


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(); ?>


3

Something like this might work: $args = array( 'post_type' => 'post', 'tax_query' => array( array( 'taxonomy' => 'your_custom_taxonomy', 'operator' => 'EXISTS' ), ), ); $query = new WP_Query( $args ); You are basically asking for any post assigned to any term within your_custom_taxonomy.


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

I FINALLY figured it out. Phew. Answer is as follows: add_action( 'woocommerce_after_subcategory', 'my_add_cat_description', 12); function my_add_cat_description ($category) { $cat_id=$category->term_id; $prod_term=get_term($cat_id,'product_cat'); $term_meta = get_option( "taxonomy_$cat_id" ); echo '<div ...


2

In general you can't. ID numbers given at one site might be already used at another.


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

https://pl.wordpress.org/plugins/taxonomy-terms-order/ This plugin does what you want, you can easily manage order.


2

You could set up a custom post type with custom taxonomies and then allow people to filter the results or do a search. Failing that, perhaps an event plugin would help. It depends on how much coding you want to do or if you want to try and find a plug and play solution.


0

How about ordering by count? $categories = get_terms( 'category', array( 'orderby' => 'count', ) ); Reference: get_terms


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

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 ...



Top 50 recent answers are included