Show audio player only in specific post type category

Have you tried has_category? You can add a check to make sure the post has the specified category. If not then return the content un changed like below: <?php add_filter( ‘woocommerce_short_description’, ‘wpse_67108_autplay_music’ ); function wpse_67108_autplay_music( $content ) { if ( ! is_singular( ‘product’ ) && ! has_category( ‘<your specific category here>’ )) { return $content; … Read more

Automatically add custom taxonomy to posts in a category

You’ll want to hook onto the wp_insert_post action. Once the new post is created, you can then assign it to the taxonomy/term you wish. It might look something like this: add_action(‘wp_insert_post’, function($postId, $post, $updatingExisting) { if( $updateExisting ) return; // read up on these params at http://developer.wordpress.org/reference/functions/wp_set_post_terms/ wp_set_post_terms( $postId, ‘main_podcast’, ‘qtserie’, true); }, 10, 3); … Read more

Inline If statement to echo CSS [closed]

It may helpful to you… $video = (in_category ( 42 )) ? ‘has-video’ : ”; echo ‘<section id=”cooked-recipe-list-‘ . $list_id_counter . ‘” class=”cooked-clearfix cooked-recipe-‘ . $list_style . ‘ cooked-recipe-loader’ . ( in_array( $list_style, $masonry_layouts ) ? ‘ cooked-masonry’ : ” ) . ( isset($atts[‘columns’]) && $atts[‘columns’] ? ‘ cooked-columns-‘ . $atts[‘columns’] : ” ) . … Read more

Get Categories of multiple posts

global $wpdb; $post_ids = [1,2,3] //Array of all post ids // get all category id’s based on post ids $result = $wpdb->get_results( ” select term_taxonomy_id from ” . $wpdb->prefix . “term_relationships where object_id in (implode(“,”,$post_ids)) );

How do I make an array to get the category name, dynamically, in an archive template?

You can try something like: if ( is_category() ) { $cat = get_category( get_query_var( ‘cat’ ) ); // $cat_id = $cat->cat_ID; $cat_name = $cat->name; // $cat_slug = $cat->slug; $args = array( ‘category_name’ => $cat_name, ‘post_type’ => ‘post’, ‘orderby’ => ‘menu_order’, ‘order’ => ‘DESC’, ); … The function you are looking for is get_category, as well … Read more