New answers tagged

0

If you want to show the same for a single post in 2020, you can check my answer here: Display only deepest category on a single post?


0

I come to this post as i was looking for the code. But the marked answer not working for me anymore. I have wrote a function to get the deepest level category assigned to a post. function post_deepest_level_cat($post_categories) { foreach ($post_categories as $category) { $cat_ids[] = $category->term_id; } $tree_args = array( ...


0

Figured it out. Missed the concatenated class dot for the data-filter attribute... Changed this line: echo '<button id="category-filter" data-filter="'.$term->slug.'">'.$term->name.'</button>'; To this: echo '<button id="category-filter" data-filter="' . '.' .$term->slug.'">'.$term->name.'...


0

I found a problem. I had to change this: $args = array( 'cat' => $category->name, 'posts_per_page' => 3,); for this: $args = array( 'category_name' => $category->name, 'posts_per_page' => 3,); In first code I was passing category name which is string to argument expecting ID of category. Here is Codex reference where I ...


0

After some time with WPML support and with some debugging/digging in the theme's core files, I found where the breadcrumb was created. I pointed this out in the support and to also add the taxonomy on pages also in their filtered queries. I was using default WordPress queries and I was aware that taxonomies on pages are not the default use in WordPress. Also,...


0

Sorry but y don't have enought reputation for comment in @bencergazda answer. I find this the best solution. But i had a error with the image show in header theme, because donĀ“t get the correct post-id. For solution i'll add the text line in the code: "global $post; $post->ID = $matchingPage->ID;" The result function loadPageFirst() { // ...


0

The function get_category_parents will get you a string of the parent categories given the ID of a child category. So, like this: $cat = $wp_query->get_queried_object(); $catid = $cat->cat_ID; $parentcats = get_category_parents ($catid, false, '|', false); This will give you something like category1|category2|category3. Follow the link above to see ...


1

You've got an extra closing bracket if (is_testimonial_category()) == $ptitle ) : should be if ( is_testimonial_category() == $ptitle ) :


1

Because the parameter name is title_li and not title_li=. It also doesn't make sense of using __( '' ), so I'd change that to just ''. // When the args is a query string, title_li= works. $args = 'title_li='; // But when the args is an array, use just title_li. $args = array( 'title_li=' => '', // bad 'title_li' => '', // good );


1

Working Example in Oct 2020, Working answer, I went to different answers none of them works now in new WordPress. function hide_categories_for_specific_user( $exclusions, $args ){ if ( ((defined( 'REST_REQUEST' ) && REST_REQUEST) or $GLOBALS['pagenow'] === 'edit.php' ) && !current_user_can( 'manage_options' ) ) { // IDs of terms to be ...


0

I had no idea if this was somehow related to wordpress configuration, or yoast, but I learned that this error was caused by the redirection plugin. It was monitoring permalink changes and created records that it didn't need to, and associating new pages with those records. Deactivating the plugin allowed me to create new pages with the intended URL.


1

If you can setup url query parameters and when user navigates to tagfillterPage page with wp_query it should work. https://examples.com/tagfillterPage/?filltertag=tagname $querytag = $_GET['filltertag']; $args = array( 'tag' => $querytag ); // Custom query. $query = new WP_Query( $args ); // Check that we have query results. if ( $query->...


0

You'll find an appropriate filter in the get_terms function which is called by get_categories. See source code https://github.com/WordPress/WordPress/blob/master/wp-includes/taxonomy.php#L1247 We don't use any of the callback arguments in this case. We can use array_filter on the list of terms (WP_Term) objects. See https://developer.wordpress.org/reference/...


0

Resolved using this: <div> <ul> <?php $current_category = get_queried_object(); ////getting current category $args = array( 'post_type' => 'page',// your post type, 'orderby' => 'menu_order', 'order' => 'DESC', 'cat' => $current_category->cat_ID // ...


0

IDs are your friends. Get the category list using get_category (i'm assuming we are talking about the in-built Wordpress "category" taxonomy, which slug is category). $categories = get_categories( array( 'hide_empty' => false // This is optional ) ); Use the obtained category list in the output of your <select> field: <?php // get ...


-1

you can try this code: $parent_cat = get_query_var('cat'); wp_list_categories("child_of=$parent_cat&show_count=1"); you will get a list of top-level categories at the output if you need an example of selecting a category, you can do this: $args = array( 'taxonomy' => 'tags', 'parent' => 0, // get top level categories ...


0

'post_not_in' => array($post_id), Here is your problem, and there are two of them: The parameter key is misspelt There's a massive performance hit that can be easily avoided Using the Correct Key It should be post__not_in not post_not_in. This will restore the desired behaviour, but with a huge performance hit that gets heavier as the size of the ...


3

You can use the WooCommerce hook woocommerce_after_add_to_cart_button. This hook will add content after the "Add To Cart" button. If the customer clicks on this button, the product should get added to the cart, and the customer should be send to the checkout page. Add the below code in your child theme functions.php /* Create Buy Now Button ...


Top 50 recent answers are included