New answers tagged

0

$leaderQuery->the_post() should only be called once, right after the loop starts: while ( $leaderQuery->have_posts() ) { $leaderQuery->the_post(); // call it just once ... } I could also see you're not correctly retrieving the ID of the current post in the loop, so the correct way is use get_the_ID(). $postCategories = get_the_category( ...


1

This will depend on how your theme is structuring the templates for single.php (individual post view) but I'll show you what to look for and how to apply via CSS. So from a theme I'm working on, this is where the category gets included in the post: <article id="post-3417" class="post-3417 post type-post status-publish format-standard hentry ...


0

I presume here that you're using a shopping cart system such as WooCommerce?? If that's the case, you could create new taxonomy terms for the products cut that WooCommerce creates using something like the below: // Create custom taxonomy for parts CPT add_action( 'init', 'create_vehmake_taxonomy' ); function create_vehmake_taxonomy() { register_taxonomy( ...


1

So you can quickly achieve this by changing 'category' to 'genre' you can do this in Settings > Permalinks and change 'Category Base' to 'genre'. To do it with code and keep both 'category' and 'genre' as prefixes is possible with a rewrite rule, however someone else may know a better way. You also need to only run flush_rewrite_rules() once so you need ...


1

You can use the exclude parameter: 'exclude' (array|string) Array or comma/space-separated string of term IDs to exclude. If $hierarchical is true, descendants of $exclude terms will also be excluded; see $exclude_tree. See get_terms(). So with your $args: $args = array( 'hide_empty' => true, 'title_li' => '', 'show_count' => 0, '...


1

The parser has the problem with usage of ", because it is not possible what is for PHP or for the syntax to echo. So change them like. $post_category = get_the_category()['0']->term_id; if ($post_category == 75) { echo '<meta name="theme-color" content="#B7E0D2">'; } else { echo'<meta ...


-1

How can I display only the specific category when accessing the posts related to that category? For example, I want to show only CSR Events under Categories When accessing posts related to CSR events. Here's the link to CSR post https://www.mi-eq.com/blood-donation-compaign/ Screenshot: https://i.stack.imgur.com/YoTfk.jpg Similarly, when visiting posts ...


0

Can't answer your question, but I just had a poke around with Query Monitor and this is the query that seems to get all the categories (it runs last so you don't have to search through every single query). If you can be bothered running this against your database and having a poke around with the results might help you figure out what's going on. Or maybe ...


0

It seems like you should use hierarchies of categories, because it sounds like 'Tiger' belongs to the group 'Animals'. You can get the parent category with $category->parent so if page category was Tiger, and parent category was Animals, this would then work. Let me know if that would work for you and if you need more info


0

It looks like wp_list_categories($args) will output directly when you call it, which is why the output comes out in a weird place. and ideally what you need is to capture the output and return it, but luckily wp_list_categories allows you to do this with the 'echo' parameter. Try: $args['echo'] = FALSE; return wp_list_categories($args); Note the extra '...


0

You can't do it using simple for/foreach loops. This is an excellent example where a recursion can help: function get_categories_list( $parent, $use_toggle = true ) { $result = ""; $categories = get_categories( array ( 'parent' => $parent ) ); if ($categories) { foreach ($categories as $category) { $name = $...


0

Try this selector: if ($('div#category-all ul.children input:checked').length) { // at least one of the child categories is selected }


1

The WP function get_category_link() will do the trick. /** * Gets the URL for a category term archive based on the category's slug. * * @param string $category_slug The slug of the category to get the category arcive for. * * @return string The category (term) archive URL. Empty string on error. */ function wpse_get_category_url_by_slug( $category_slug ...


0

I tried to follow the code above but to no avail. How can i hide Company News categories when accessing posts related to CSR events category? Please see page link below: https://www.mi-eq.com/blood-donation-compaign/


1

This part of code from the question will fetch only parent category because 'parent' => 0, drop this from array if you need all the categories $categories = get_categories( array( 'orderby' => 'name', 'parent' => 0 ) ); // You can iterate over the list of objects returned by `get_categories` // to achieve list of categories in required ...


0

https://wordpress.org/plugins/category-posts/ try this one - I think this is should work for what you are trying to accomplish


0

This solved my issue, originally created by Mr. Prashant Singh @ WordPress forum $args = array( 'posts_per_page' => -1, 'tax_query' => array( 'relation' => 'AND', // only posts that have both taxonomies will return. array( 'taxonomy' => 'post_tag', 'field' => 'slug', 'terms' => 'your-tag-slug', //cat ...


0

I recently wrote a bit of code which filters by one tag at a time only, but it would be pretty easy to modify it to 'toggle' the status of each tag so that you could filter by multiple tags simultaneously. You can see it working here: http://sadcookbook.recipes/sad/ . It uses the following PHP to render the tag links, Show only: <?php $tags = get_tags();...


0

This will check to see if there is a hierarchy and set all parent categories as checked. This function assumes that if there's multiple categories already set, then don't do the function, since the categories would be correct if multiples are set. function set_product_parent_categories( $post_id ) { $category = wp_get_post_terms( $post_id, 'product_cat' ...


0

After some research I came up with the following // Get the posts in that category with the required tag $args = array( 'post_type' => ['documents','news'], 'fields' => 'ids', // Only get post IDs 'posts_per_page' => -1, 'tax_query' => array( array( 'taxonomy' => 'forms', 'field' ...


Top 50 recent answers are included