• Resolved genesisbits

    (@genesisbits)


    Love the plugin, been using it for ages now.

    I have a plugin that basically searches and filters my posts. It has the option to “sort” these posts using a “meta value“. It seems WPP doesn’t have a meta value as I was hoping it would have some sort of “wpp_view_number” meta value or something along those lines.

    Is it possible to create this for the plugin and assign it to all posts? Or is there actually a meta value already there that’s possibly hidden?

    Thanks!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Hector Cabrera

    (@hcabrera)

    Hi there!

    No, WPP doesn’t store any meta data in your database (althought I’ve been thinking for a while that it probably should, might come in handy in the future.)

    Fortunately, if you follow the first step from this post you’ll get what you need ??

    Thread Starter genesisbits

    (@genesisbits)

    Thanks for that! Got it working.

    Wasn’t initially working (my plugin was sorting the new meta value weirdly). Eventually figured out that it may have been the comma with the way the views are stored: 24,198.

    So I changed one of the lines in the link you gave me to this:
    update_post_meta( $postid, 'total_views', str_replace( ',', '', wpp_get_views( $postid ) ) );

    and it worked perfectly.

    Plugin Author Hector Cabrera

    (@hcabrera)

    Glad to know you got it working ??

    Regarding the number format, the wpp_get_views() template tag has a third parameter that you can use to enable / disable number formatting, so your code becomes something like this:

    update_post_meta(
        $postid,
        'total_views', 
        wpp_get_views( $postid, 'all', false )
    );
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘meta value for Views?’ is closed to new replies.