Conditional loop for category

$categories = get_categories( array( ‘parent’ => 0, ) ); foreach ( $categories as $category ) { echo $category->name; $posts = get_posts( array( ‘category_name’ => $category->slug, ‘posts_per_page’ => 3, ) ); foreach ( $posts as $item ) { echo get_the_title( $item->ID ); } } Something like this print wich you need. But it is very simple … Read more

How to automatically check multiple categories on new post

The filter you’re looking for is called wp_terms_checklist_args and is used by wp_terms_checklist() (which is internally called to display the category metabox). You can use this to pre-selected specific categories (by ID) under certain circumstances as shown in this example add_filter(‘wp_terms_checklist_args’, ‘WPSE_pre_select_categories’, 10, 2); function WPSE_pre_select_categories($args, $post_id) { $post = get_post($post_id); // only pre select … Read more

Display single category name in woocommerce loop

<?php remove_action(‘woocommerce_shop_loop_item_title’, ‘woocommerce_template_loop_product_title’, 10); function loop_title() { global $post;?> <div class=”col-xl-3 col-md-3 col-sm-3″> <h3><a href=”https://wordpress.stackexchange.com/questions/304779/<?php the_permalink(); ?>” class=”feed-item-baslik”><?php the_title(); ?></a></h3> <?php $terms = get_the_terms( $post->ID, ‘product_cat’ ); if ( $terms && ! is_wp_error( $terms ) ) : if ( ! empty( $terms ) ) { echo $terms[0]->name; }?> <?php endif;?> </div> <?php } add_action(‘woocommerce_shop_loop_item_title’, ‘loop_title’, … Read more

Getting All Post From Specific category in wpdb

Well, there are many things that are not exactly correct with your code: $posts = $wpdb->get_results( “SELECT ID, post_title, post_modified_gmt FROM $wpdb->posts LEFT JOIN $wpdb->term_relationships as t ON ID = t.object_id WHERE post_type=”post” AND post_status=”publish” AND t.term_taxonomy_id = 3 WHERE post_status=”publish” # <– !! second WHERE clause AND post_password = ” AND post_type=”post” # <– … Read more

show all WordPress categories in a page

To get link to category use the function get_category_link (doc here). Function get_permalink is intended for posts. echo ‘<h2 class=”podcast_h2″><a href=”https://wordpress.stackexchange.com/questions/310553/” .get_category_link($category->term_id). “https://wordpress.stackexchange.com/questions/310553/”> ‘.$category->name.’ </a></h2>’

Count category views – Is it possible?

WordPress doesn’t record the visit statistics in the database. If you want to show top visited categories, you must then record statistics somewhere. What’s why there are plugins designed to fill out this need. Of course, you can write your own code to record visits in the database. This will be a good starting point.