The effects of alcohol on sustanon 250 leucine for – real weight loss & bodybuilding benefits?
Search
Close
AI Search
Classic Search
 Search Phrase:
 Search Type:
Advanced search options
 Search in Forums:
 Search in date period:

 Sort Search Results by:

AI Assistant
filter comment with...
 
Share:
Notifications
Clear all

[Solved] filter comment with custom field

6 Posts
2 Users
4 Reactions
2,543 Views
Posts: 4
Topic starter
Translate
English
Spanish
French
German
Italian
Portuguese
Russian
Chinese
Japanese
Korean
Arabic
Hindi
Dutch
Polish
Turkish
Vietnamese
Thai
Swedish
Danish
Finnish
Norwegian
Czech
Hungarian
Romanian
Greek
Hebrew
Indonesian
Malay
Ukrainian
Bulgarian
Croatian
Slovak
Slovenian
Serbian
Lithuanian
Latvian
Estonian
(@vahid13713)
Active Member
Joined: 4 years ago
[#3583]

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: 8208
 Asti
Support
Translate
English
Spanish
French
German
Italian
Portuguese
Russian
Chinese
Japanese
Korean
Arabic
Hindi
Dutch
Polish
Turkish
Vietnamese
Thai
Swedish
Danish
Finnish
Norwegian
Czech
Hungarian
Romanian
Greek
Hebrew
Indonesian
Malay
Ukrainian
Bulgarian
Croatian
Slovak
Slovenian
Serbian
Lithuanian
Latvian
Estonian
(@asti)
Illustrious Member
Joined: 8 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: 4 years ago

Active Member
Posts: 4
Translate
English
Spanish
French
German
Italian
Portuguese
Russian
Chinese
Japanese
Korean
Arabic
Hindi
Dutch
Polish
Turkish
Vietnamese
Thai
Swedish
Danish
Finnish
Norwegian
Czech
Hungarian
Romanian
Greek
Hebrew
Indonesian
Malay
Ukrainian
Bulgarian
Croatian
Slovak
Slovenian
Serbian
Lithuanian
Latvian
Estonian

@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: 8 years ago

Illustrious Member
Posts: 8208
Asti
Translate
English
Spanish
French
German
Italian
Portuguese
Russian
Chinese
Japanese
Korean
Arabic
Hindi
Dutch
Polish
Turkish
Vietnamese
Thai
Swedish
Danish
Finnish
Norwegian
Czech
Hungarian
Romanian
Greek
Hebrew
Indonesian
Malay
Ukrainian
Bulgarian
Croatian
Slovak
Slovenian
Serbian
Lithuanian
Latvian
Estonian

@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: 4 years ago

Active Member
Posts: 4
Asti
Translate
English
Spanish
French
German
Italian
Portuguese
Russian
Chinese
Japanese
Korean
Arabic
Hindi
Dutch
Polish
Turkish
Vietnamese
Thai
Swedish
Danish
Finnish
Norwegian
Czech
Hungarian
Romanian
Greek
Hebrew
Indonesian
Malay
Ukrainian
Bulgarian
Croatian
Slovak
Slovenian
Serbian
Lithuanian
Latvian
Estonian

@asti 

 

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


(@vahid13713)
Joined: 4 years ago

Active Member
Posts: 4
Asti
Translate
English
Spanish
French
German
Italian
Portuguese
Russian
Chinese
Japanese
Korean
Arabic
Hindi
Dutch
Polish
Turkish
Vietnamese
Thai
Swedish
Danish
Finnish
Norwegian
Czech
Hungarian
Romanian
Greek
Hebrew
Indonesian
Malay
Ukrainian
Bulgarian
Croatian
Slovak
Slovenian
Serbian
Lithuanian
Latvian
Estonian

@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: