borkolivic

Shortcode for showing product count per author

Mar 18th, 2022 (edited)
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.44 KB | None | 0 0
  1. add_shortcode( 'products-counter', 'products_counter_shortcode' );
  2. function products_counter_shortcode( $atts ) {
  3.    
  4.     $atts = shortcode_atts( [
  5.         'author' => '',
  6.     ], $atts );
  7.    
  8.     $the_user = get_user_by('login', $atts['author']);
  9.     $userid = $the_user->ID;
  10.    
  11.    
  12.     return 'Broj objavljenih proizvoda: ' . $atts['author'] . ' ' . count_user_posts($userid, 'product', true);
  13. }
  14. /* shortcode usage [products-counter author="username1"]
Add Comment
Please, Sign In to add comment