Categories list loop – add separator every 3 categories [closed]

<?php $args=array( ‘orderby’ => ‘name’, ‘order’ => ‘ASC’, ) $count=1; // A $count variable ?> <?php foreach (get_categories( $args ) as $cat) : if($count%3==0) // This condition will be true for 3,6,9,12………. { //Your Code — } $count++ // Increment $count variable ?> <h3><a href=”https://wordpress.stackexchange.com/questions/246349/<?php echo get_category_link($cat->term_id); ?>”><?php echo $cat->cat_name; ?></a></h3> <a href=”https://wordpress.stackexchange.com/questions/246349/<?php echo get_category_link($cat->term_id); … Read more

Display Posts on Custom Page

If News is a category of posts, then: First, find out the category ID, login to wp-admin, go Posts->Categories, mouse over the ‘News’ category, and cat id should be shown under the left corner of the browser (for chrome this works, not sure about other browsers). Add the following code into your function.php function my_news_category( … Read more

How many posts does the loop return?

Try reversing the logic, put the dividing line before the post but only do it after the first post. To answer your question though, you can get the loop count with the following: global $wp_query; $count = count( $wp_query->posts ); // or $count = $wp_query->post_count;

Variable not being passed into WordPress loop

If $my_share echoes as “5171,5167,5165” then it is a string not an array… In other words array($string) does not equal array(integer,integer,integer) even if $string equals “integer,integer,integer” because array treats $string as a single value with further values separated by commas. You could use post__in => explode(“,”, $my_share), to convert the string into an array while … Read more

Can we count the WordPress Loop

$wp_query->current_post is the build-in loop counter, starting with 0 zero for the first post in the loop. so the line some code to be executed could translate to: <?php if( $wp_query->current_post > 0 && $wp_query->current_post % 5 == 0 ) { ?> some code to be executed <?php } ?>

Sort posts in loop by the WooCommerce Membership of the author

I would flag post as member_post when it is submitted to database and use this flag to sort them. function wpse_287048_flag_member_post( $post_id ) { if ( wc_memberships_get_user_active_memberships() !== false ) { // Check if user is member update_post_meta( $post_id, ‘member_post’, 1 ); } else { update_post_meta( $post_id, ‘member_post’, 0 ); } } add_action( ‘save_post’, ‘wpse_287048_flag_member_post’ … Read more