Array as ‘key’ in WP_Query
In addition to the suggestion by @AhmedMahdi to solve your problem, here’s the narrower answer to your question: Nope, key cannot be an array. As you can see in the specs of WP_Meta_Query key must be a string.
In addition to the suggestion by @AhmedMahdi to solve your problem, here’s the narrower answer to your question: Nope, key cannot be an array. As you can see in the specs of WP_Meta_Query key must be a string.
<?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
If have_posts() is true, there is a global WP_Query object available. And that has a post count already: if ( have_posts() ) { print $GLOBALS[‘wp_query’]->post_count; } There is no need for a custom count.
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
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;
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
$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 } ?>
There are two steps to get this working: Add a counter to your main loop, so you can check how many posts are output. If your counter is less than 3, run a second query and output. So for step 1, set a counter before your loop and increment it each time the loop runs, … Read more
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
You should use $product->get_price() take a look at WooCommerce WC_Product class.