The effects of alcohol on sustanon 250 leucine for – real weight loss & bodybuilding benefits?
filter comment with...
 
Share:
Notifications
Clear all

[Solved] filter comment with custom field

6 Posts
2 Users
4 Reactions
1,705 Views
Posts: 4
Topic starter
(@vahid13713)
Active Member
Joined: 3 years ago

Hello, How can I filter the comments displayed under a page based on a custom field? For example, if the custom field has a value of a, that comment should be displayed, and if it does not have this value, it should not be displayed.

5 Replies
Asti
Posts: 7661
 Asti
Support
(@asti)
Illustrious Member
Joined: 7 years ago

vahid13713,

If you're a developers you can use the get_comments() and get_comment() functions. 

Also, we have plugin customization and custom addon development services at the gVectors Team. They can assess the work and create it for you. Just contact us via sales[at]gvectors.com email address and send a list of requirements you'd like to have.

4 Replies
(@vahid13713)
Joined: 3 years ago

Active Member
Posts: 4

@asti 

Hello asti and thank you very much for your answer
I am a developer.

I get the comment with the  get_comments() function and I want wpdiscuz to show only the comments I received. How can I do this?  Please provide me with a sample code 

 

my sample code:

    $comments20 = get_comments (array ('meta_key'=> 'keytoopurl', 'meta_value'=> 'y'));

I want wpdiscuz to display only variable  comments20 

 

How can I do this?

 

 

Thanks for your cooperation

 

 

Asti
 Asti
Support
(@asti)
Joined: 7 years ago

Illustrious Member
Posts: 7661

@vahid13713,

Please use this code: 

add_action('pre_get_comments', function ($queryObj) {
            $vars = $queryObj->query_vars;
            $vars['meta_key'] = 'keytoopurl';
            $vars['meta_value'] = 'y';
            $queryObj->query_vars = $vars;
    });
(@vahid13713)
Joined: 3 years ago

Active Member
Posts: 4

@asti 

 

Thank you very much for your answer
I tested this code but it does not work. All comments are displayed!

(@vahid13713)
Joined: 3 years ago

Active Member
Posts: 4

@asti 

 

Hi, I have fixed the problem. I am posting content for others to use.
Your plugin caches comments, which is why our code does not work. Also, after writing the filter, it is necessary to activate and deactivate the plugin once. The problem was solved by adding the following line of code.

 

 

add_action('pre_get_comments', function ($query)
{
    $query->query_vars['meta_query'] = [
        [
            'key' => 'keyurl',
            'value' => "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"
        ]
    ];
}, 10, 1);
Share: