How can I ask to an existing category?
If you want to check whether a certain post has a certain category, you need in_category, so your test would need to be: if (in_category($category_name))
If you want to check whether a certain post has a certain category, you need in_category, so your test would need to be: if (in_category($category_name))
No, you cannot (easily) choose what tag ID is assigned. It’s not random – it’s the next ID available after the last one that was created in the database. If you really want to control tag IDs, you’ll need to clear your database and start fresh, and create each tag in the order you want … Read more
Since you’re using a custom taxonomy, you can’t use the category argument. You can find some information about custom taxonomy retrieval in this comment in the developer documentation. According to that, I think your $categoryArgs should be: $categoryArgs = array( ‘orderby’ => ‘post_date’, ‘order’ => ‘DESC’, ‘post_type’ => $type, ‘tax_query’ => array( array( ‘taxonomy’ => … Read more
You can use the function in_category to test if a post is in a certain category. It takes one or more categories and the post as input. So you may differentiate your function like this: function title_content($atts, $content = null ) { global $wpdb; $post_id = $wpdb->get_var($wpdb->prepare(“SELECT ID FROM {$wpdb->posts} WHERE post_title = %s”,$content)); $getpost … Read more
This sounds interesting – that’s not how the front page in WordPress usually works. By default, all your latest posts will display unless you specifically set a certain page (not post) to act as your home page through Settings -> Reading. It sounds as if your theme is doing something a little bit custom. Having … Read more
Assuming it is a page template that is not set to Blog Posts Page: Using pre_get_posts to show only one category doesn’t work as the main query contains only page content and is not a post loop. So we can do this using a secondary query using WP_Query. Look at WP_Query category parameters <?php $args … Read more
Instead of using the_category, I would just build the category links manually and add the category slug as the class name. Something like this: <span class=”post_into”> <?php $thelist=””; $i = 0; foreach( get_the_category() as $category ) { if ( 0 < $i ) $thelist .= ‘, ‘; $thelist .= ‘<a href=”‘ . esc_url( get_category_link( $category->term_id … Read more
You can try below code. Below code shows search box and woocommerce product categories . It will also show selected category. <form name=”myform” method=”GET” action=”<?php echo esc_url(home_url(“https://wordpress.stackexchange.com/”)); ?>”> <?php if (class_exists(‘WooCommerce’)) : ?> <?php if(isset($_REQUEST[‘product_cat’]) && !empty($_REQUEST[‘product_cat’])) { $optsetlect=$_REQUEST[‘product_cat’]; } else{ $optsetlect=0; } $args = array( ‘show_option_all’ => esc_html__( ‘All Categories’, ‘woocommerce’ ), ‘hierarchical’ => … Read more
You could hook to the get_terms_args filter conditionally depending on your user/role Something along those lines add_filter( ‘get_terms_args’, ‘restrict_cat’, 10, 2 ); function restrict_cat( $args, $taxonomies ){ // Don’t run if we are not dealing with categories if( ‘category’ != $taxonomies[0] ) return $args; // The check for the user we want to restrict // … Read more
Another idea (which heavily depends on what you are viewing [single or archive] and also your taxonomy-structure) is to look for the term parent. Maybe this can help you aswell … You were asking about “highest category in the hierarchy for a specific post”. Example: A post is associated with 3 terms of an taxonomy … Read more