Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am new in PHP and WordPress and I am personalizing an existent template and I have the following problem.

In the function.php file of the template I have the following function:

function admired_posted_on() {
    printf( __( '<span class="sep">Posted on </span>
                 <a href="%1$s" title="%2$s" rel="bookmark">
                    <time class="entry-date" datetime="%3$s" pubdate>%4$s</time>
                 <span class="by-author"> 
                    <span class="sep"> by bla</span> 
                    <span class="author vcard">
                        <a class="url fn n" href="%6$s" title="%7$s" rel="author">%8$s</a>
                 ', 'admired' ),

    esc_url( get_permalink() ),
    esc_attr( get_the_time() ),
    esc_attr( get_the_date( 'c' ) ),
    esc_html( get_the_date() ),
    sprintf('Views: ', get_PostViews(get_the_ID())),
    esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
    sprintf( esc_attr__( 'View all posts by %s', 'admired' ), get_the_author() ),
    esc_html( get_the_author() )

As you can see this function create some HTML code that will print in a specific part of my template (inside a loop).

Ok, as you can see this line:

sprintf('Views: ', get_PostViews(get_the_ID())),

should print the string "Views:" followed by the value returned by the function get_the_ID() (that rappresent the number of person that read a post)

As you can see this function is the fifth called in the list of called function, so this value should be put instead of the %5$s placeholder, into the following span tag:


The proble is that whem I go to execute my page in this span appear only the value: Views: but don't appear the output of the get_PostViews() function.

If instead of the original line:

sprintf('Views: ', get_PostViews(get_the_ID())),

I use this line:


it work well but so I can't preappend the explaination text: "Views:"

Why? what can I do to print the "Views" text followed by the returned value of my get_PostViews function?



share|improve this question

closed as off topic by Chip Bennett, toscho Mar 25 '13 at 18:19

Questions on WordPress Development Stack Exchange are expected to relate to WordPress within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.

This is a PHP / sprintf() issue, not a WordPress issue. –  Chip Bennett Mar 25 '13 at 17:56
I'm not sure the questioner knows that. –  vancoder Mar 25 '13 at 18:06

1 Answer 1

up vote 1 down vote accepted

There is no specifier in your sprintf, so it won't output anything. Try:

sprintf('Views: %d', get_PostViews(get_the_ID())),

You may have to use %s instead, it depends what your get_PostViews function is returning.

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.