Shortcode with product catgory counter

Try this: (add it to the theme’s main functions.php file) add_shortcode( ‘products-counter’, ‘products_counter’ ); function products_counter( $atts ) { $atts = shortcode_atts( [ ‘category’ => ”, ], $atts ); $taxonomy = ‘product_cat’; if ( is_numeric( $atts[‘category’] ) ) { $cat = get_term( $atts[‘category’], $taxonomy ); } else { $cat = get_term_by( ‘slug’, $atts[‘category’], $taxonomy ); … Read more

Redirect based on user post count

add_action( ‘template_redirect’, ‘redirect_to_specific_page’ ); function redirect_to_specific_page() { global $post; $current_user = $post->post_author; if(!empty($current_user)){ $user_post_count = (int) count_user_posts( $current_user ); if ( is_page(‘butiktest’) && $user_post_count == 1 ) { wp_redirect( ‘enhytte’, 301 ); exit; } } } authorized user: $current_user = wp_get_current_user();

Specific Loop For 2 Within Each

i use this code in my portfolio http://pocketapps.co/ <?php $args = array( //your argument code ); query_posts($args);?> <ul> <?php $ls=0; while ( have_posts() ) : the_post(); ?> <?php if($ls%2==0): echo ‘</li><li>’; endif; ?> <div class=”app”> //your code here </div> <?php $ls++; endwhile; wp_reset_query(); ?> </ul>

Insert html after certain amount of posts?

You could use the following and it should do exactly what you want by checking the value of $loop->current_post. <?php $loop = new WP_Query( array( ‘post_type’ => ‘work’,’posts_per_page’ => ‘-1’ ) ); ?> <ul id=”carousel”> <li> <ul class=”inner-items”> <?php while ( $loop->have_posts() ) : $loop->the_post(); ?> <?php if( $loop->current_post && !($loop->current_post % 6) ) : … Read more

Add character count to custom metabox

I assume the #feed element is the one in which you want the count value to appear? If so, change the #bgnp_metabox_tabs entry in your keyup function to #feed. EDIT: For some reason, I wasn’t seeing all the code when I first read the problem. The id of your placeholder for the character count is … Read more

How to use global post counter in the loop?

As I already stated in a comment, You need to use get_option( ‘posts_per_page’ ) and get_query_var( ‘paged’ ) to calculate your post numbers You can do something like the following: (I have commented the code to make it easy to follow. This goes into functions.php) function get_post_number() { global $wp_query; /* * Get current page … Read more

Network wide post count (WP Multisite)

You don’t seem to call posts_count_func() anywhere, so if your transient expires, it’s not getting reset. function posts_shortcode_count_func( $atts ){ $post_count = get_site_transient( ‘total_posts_cache’ ); if( ! $post_count ) { posts_count_func(); $post_count = get_site_transient( ‘total_posts_cache’ ); } return $post_count; } add_shortcode( ‘posts’, ‘posts_shortcode_count_func’ ); According to the docs for get_transient() (which is the non-network version … Read more

Problem with get_posts, tax_query and counting the number of posts

Try this again removing operator and relation arguments as follows: here is a useful link http://ottopress.com/2010/wordpress-3-1-advanced-taxonomy-queries/ $products = get_posts(array( ‘post_type’ => ‘products’, ‘posts_per_page’ => -1, ‘post_status’ => ‘publish’, ‘tax_query’ => array( array( ‘taxonomy’ => ‘collection’, ‘field’ => ‘slug’, ‘terms’ => array($current_collection) ), array( ‘taxonomy’ => ‘type’, ‘field’ => ‘slug’, ‘terms’ => array($current_type) ), array( ‘taxonomy’ … Read more

Limit tag word count

Use the pre_insert_term filter: function wpse_189722_limit_tag_words( $term, $taxonomy ) { if ( $taxonomy === ‘post_tag’ ) { if ( count( preg_split( ‘/\s+/’, trim( $term ) ) ) > 2 ) $term = new WP_Error( ‘term_too_many_words’, ‘Maximum of 2 words’ ); } return $term; } add_filter( ‘pre_insert_term’, ‘wpse_189722_limit_tag_words’, 10, 2 );

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)