Wordpress: Can you query Anonymous comments?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Wordpress: Can you query Anonymous comments?

Post by simonmlewis »

We have a commerce site that imported 10,000s of star ratings, and they were added in the Reviews section.

We have decided to see if we can query the review, and if it is Anonymous, which these all are, then to hide the 'author', remove the date (as they are all the same date), and add text to say "Star rating only given".

If reviews have an author, then it will show everything.

I don't know how to even start to accomplish this. ie. is it in single-product.php or review.php. Once would thing it would be a function we need to write, but no idea how to.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
protopatterns
Forum Newbie
Posts: 9
Joined: Sun Jan 28, 2018 11:18 am

Re: Wordpress: Can you query Anonymous comments?

Post by protopatterns »

I assume this is WooCommerce ('single-product.php'). Why not start with the db?

The users themselves:
https://deanandrews.uk/export-woocommer ... wordpress/

And the ratings:
https://wordpress.stackexchange.com/que ... est-design

You can remove the author (etc) in your theme itself, here: wp-content/themes/[theme-name]/inc/template-tags.php

Just modify 'function themename_posted_on()' right before the end, e.g.:

Code: Select all

    // Very bottom of 'theme_name_posted_on()':
    $anonymous = get_the_author();
        if ( $anonymous == "Anonymous" ) {
            // remove author, date, etc.
    } else {	
    $byline = sprintf(
        /* translators: %s: post author. */
        // ...
    }
} // End function
[ /syntax]
Post Reply