• I am trying to add a user count in this bit of shortcode:
    [statBox1 stat_image="http://www.dollarkiwi.com/wp-content/uploads/2014/08/man-icon.png" stat_percentage="0" text_color="white" class="wow fadeInUp"] Members [/statBox1]
    Where it says stat_percentage=”0″ I want the count to be where 0 is.
    Whatever I try I end up breaking the shortcode.

    Thanks for any help that anyone can offer.

Viewing 1 replies (of 1 total)
  • You may be able to do this by wrapping the shortcode in one of your own which would get the user count, insert it into the shortcode text, and do_shortcode() on the resulting text.

    The sample function below should get you started. If you are not already using a Child theme, you should create one, otherwise you changes will be lost if you update your theme.

    Add this to your child theme’s functions.php:

    function my_statBox1_function( $atts, $content = '' ) {
       global $wpdb;
       $a = shortcode_atts( array(
             'stat_image' => 'http://www.dollarkiwi.com/wp-content/uploads/2014/08/man-icon.png',
             'stat_percentage' => 0,
             'text_color' => 'white',
             'class' => 'wow fadeInUp',
       ), $atts );
       $a['stat_percentage'] = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->users" );
       $text = "[statBox1 stat_image=\"{$a['stat_image']}\" stat_percentage=\"{$a['stat_percentage']}\" text_color=\"{$a['text_color']}\" class=\"{$a['class']}\"] $content [/statBox1]";
       //return $text;  // For testing
       $result = do_shortcode($text);
       return $result;
    }
    add_shortcode( 'my_statBox1', 'my_statBox1_function' );

    Then replace the statBox1 shortcode with my_statBox1 in your post.

Viewing 1 replies (of 1 total)
  • The topic ‘Adding a user count within a shortcode’ is closed to new replies.