New answers tagged

1

This would work. As posted by @bucketpress. $someposts = get_posts( array( 'post_type' => 'work', 'posts_per_page' => -1, 'fields' => 'ids', // return an array of ids 'tax_query' => array( array( 'taxonomy' => get_query_var('taxonomy'), 'field' => 'slug', ...


0

To get all terms from all taxonomies assigned to "work" custom post type you can customize your code to look like this $taxes = array_keys( get_object_taxonomies( 'work', 'objects' ) ); $work_categorys = get_terms( [ 'taxonomy' => $taxes, 'hide_empty' => true, ] );


0

wp_get_post_terms() will return a WP_Error object if the taxonomy can't be found. So $events[0] won't exist if that happens. If you're getting this error it means that there's no taxonomy named events registered on your site. So you'll need to make sure that you've used the correct name for the taxonomy whose terms you want to list.


0

I cobbled this code together from different ideas online, and seems to work: <?php foreach ( $product_categories as $product_category ) { echo '<h2><a href="' . get_term_link( $product_category ) . '">' . $product_category->name . '</a></h2>'; $args = array( 'tax_query' => array( 'relation' =...


0

Try to apply your code into woocommerce category with tag, but it does not work. Something wrong with my code? function myplugin_rewrite_tag_rule() { add_rewrite_rule( 'store/(.+?)/product_tag/([^/]+)/?$', 'index.php?product_cat=$matches[1]&product_tag=$matches[2]', 'top' ); add_rewrite_rule( 'store/(.+?)/...


1

You shouldn't be using WP_Query at all. The standard loop will automatically display the correct posts. while ( have_posts() ) : the_post(); endwhile;


-1

You can use get_queried_object(), within that object you can get the slug or id.


0

The following function is adapted to return the root category: function get_root_category($category = null) { if (!$category) $category = get_the_category()[0]; $ancestors = get_ancestors($category->term_id, 'category'); if (empty($ancestors)) return $category; $root = get_category(array_pop($ancestors)); return $root; } Usage: ...


0

@Antti Koskinen Sorry I missexplained, this is not coming from Elementor, it is just that I do not know where to put the code :) I have modified the file class-wp-widget-search.php but it did not have any effect. I just added this to the file : 'selected' => 2, Here is complete file code : /** * Sets up a new Search widget instance. * * @since 2.8....


1

The code below works for me in archive-product.php not sure if it may also work in taxonomy-product_cat.php EDIT I've added some lines of code to exclude posts previously outputted, since a post can belong to several categories and that's why you can find always the same posts if(is_a(get_queried_object(),'WP_term')){ $subs=get_terms('product_cat',...


0

You need to create a NEW pod that is a Category type, then simply associate it with your CPT pod.


0

I think the solution that would work out best for you is just using your own query. Since you have modified pages to have categories and tags taxonomies wp_list_pages doesn't support excluding the arguments quite like that. You could get an array of all page IDs that are assigned to each category, but you'd be writing a query for that. You might as well ...


0

I actually have a large page based website that I am working on. Since it is mainly page driven, I used a function to allow categories and tags on pages. I would love to know if there is a way to exclude a category using the wp_list_pages() function. This would allow me to put in one id or slug rather than updating it with a new page id each time I have a ...


0

To set the default value for the category dropdown, you need to pass it as a parameter for the function. Like so, $dropdown_args = array( 'selected' => 2, ); wp_dropdown_categories( $dropdown_args );


0

now it displays just one (the first one) from the ticked portfolio category list, but if the first one is not from the "6" parent, then it displays nothing: If I thick those: parent 1 --child 11 --child 12 --child 13 parent 2 (ID=6) --child 21 --child 22 (X) parent 3... ... then display child 22 (it's the expected). But if I tick those: parent 1 ...


0

$current_term = get_the_terms( get_the_ID(), 'portfolio_category' ); $term_id = ''; if( !empty( $current_term ) ){ $term_id = $current_term[0]->term_id; } $args = array( 'hierarchical' => 1, 'taxonomy' => 'portfolio_category', 'hide_empty' => 0, 'parent' => 6, ); $categories = get_categories($args); ...


0

Assuming the name of your custom post type is "videos", you can create a new template file in the themes directory called taxonomy-videos.php. If your custom post type's permalinks are set up correctly this template will be rendered anytime the main query returns 'videos', so at 'http://www.yoursite.com/videos'. In the template file you can start a loop and ...


0

The solution to my problem was to use: has_term( 'the-cat-I-want-to-display', 'product_cat' ) || is_product_category( 'the-cat-I-want-to-display' ) This worked. Thanks everyone for your help!


2

A post has a js redirection script. Full Stop. If you're redirecting anything in JS, start from there as the first failure point. There's really no reason anything should be redirecting from JS on the front end. There are plenty of redirection plugins out there to handle any redirection rules you might need. Delete the script, redirect the page properly, ...


1

If that redirection script is written in the content section of the post, it is probably being called in with the rest of the content on the category page. You could add a URL check to your javascript that would look like this: if(document.URL.indexOf("foo_page.html") >= 0){ window.location.replace("http://www.w3schools.com"); } And add in your ...


0

$term_id = $current_term_id; $args = array( 'hierarchical' => 1, 'taxonomy' => 'portfolio_category', 'hide_empty' => 0, 'parent' => 6, ); $categories = get_categories($args); foreach($categories as $category) { if( $term_id != $category->cat_ID){ continue; } echo '<a ...


0

Document title renders in _wp_render_title_tag. If you want to modify it, you need to remove the WP function and create your own with similar logic. Something similar to this: remove_action('wp_head', '_wp_render_title_tag', 1); And then: add_filter('wp_head', function () { if (!current_theme_supports('title-tag')) { return; } if (...


0

You can add a filter in the title like: add_filter('the_title', function ($title) { if (is_single()) { $categories = get_the_category(get_the_ID()); // Assuming the post has many categories will take the first $category = reset($categories); return $category->name .' - '.$title; } return $title; });


0

Thank you for your help ! We are halfway there. The "All categories" only shows before anything else is selected. So I just need to change the default selected category. I used this : function wp_dropdown_categories( $args = '' ) { $defaults = array( 'selected' => 2, ); But it crashed my website.. that might not be it. Can anyone see my mistake ?


0

This list can be modified using WooCommerce filters. However, without a thorough testing I could not find a specific filter to help you. You might check the API for a better answer. Meanwhile, I have used this CSS snippet to successfully hide the "All Categories" entry from the drop-down selector: li.option[data-value=''] { display: none; } This will ...


0

Try this <?php $post_type = "post"; $taxonomy = "category"; $terms = get_terms( array( 'taxonomy' => $taxonomy, 'hide_empty' => 0, 'hierarchical'=> 1, ) ); echo '<ul>'; foreach($terms as $term): $term_id = $term->term_id; $term_name = $term->name; $query = array( 'post_type' =&...


0

You can use default wordpress function to search categories. get_terms() is the function you need to use where you need to pass your search string in a search parameter. For details please check get_terms function in wordpress codex


0

When you trying to insert child categories you are looking for term_exists() to return an array with a key term_id. Following the documentation for term_exists Return Values (mixed) Returns 0 or NULL if the term does not exist. Returns the term ID if no taxonomy was specified and the term exists. Returns an array if the parent exists. (format: ...


0

Did you try to filter the $wp_query object? You can use this code snippet to search for the category slug directly in DB: function pm_detect_term_slugs($query) { global $wpdb; // Do not run when Elementor is opened if((!empty($_REQUEST['action']) && strpos($_REQUEST['action'], 'elementor') !== false) || isset($_REQUEST['elementor-...


0

If you want to save your Tune Category as deafult category, you have to use wp_set_post_terms() with update_post_meta(). add_action( 'save_post', 'rudr_save_metaboxdata', 10, 2 ); function rudr_save_metaboxdata( $post_id, $post ) { if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ) return $post_id; // if post type is different from our ...


1

First of all you saved the the terms value in a post meta table and not following the wordpress conventional method. To make it connect with default category with that post you need to modify your save_post action. Check the modified code. add_action( 'save_post', 'rudr_save_metaboxdata', 10, 2 ); function rudr_save_metaboxdata( $post_id, $post ) { ...


Top 50 recent answers are included