PHP Developers Network
http://forums.devnetwork.net/

Wordpress Pagination Links - how do I modify this?
http://forums.devnetwork.net/viewtopic.php?f=2&t=144184
Page 1 of 8

Author:  simonmlewis [ Tue Sep 05, 2017 3:52 am ]
Post subject:  Wordpress Pagination Links - how do I modify this?

I've found this code within Wordpress. I want to be able to change the query so it only finds comments where the comments_content field is not empty.

This isn't a normal PHP query to me, so not sure how to do it. Whether I need to add a function and puts something in there, so that $comments_content is only empty when it is used. I don't know. Any help would be great.

This query is in wp-includes/link-template.php.

Syntax: [ Download ] [ Hide ]
function paginate_comments_links( $args = array() ) {
        global $wp_rewrite;

        if ( ! is_singular() )
                return;

        $page = get_query_var('cpage');
        if ( !$page )
                $page = 1;
        $max_page = get_comment_pages_count();
        $defaults = array(
                'base' => add_query_arg( 'cpage', '%#%' ),
                'format' => '',
                'total' => $max_page,
                'current' => $page,
                'echo' => true,
                'add_fragment' => '#comments'
        );
        if ( $wp_rewrite->using_permalinks() )
                $defaults['base'] = <span style='color:blue' title='I&#39;m naughty, are you naughty?'>smurf</span>(<span style='color:blue' title='I&#39;m naughty, are you naughty?'>smurf</span>(get_permalink()) . $wp_rewrite->comments_pagination_base . '-%#%', 'commentpaged');

        $args = wp_parse_args( $args, $defaults );
        $page_links = paginate_links( $args );

        if ( $args['echo'] )
                echo $page_links;
        else
                return $page_links;
}

Author:  Celauran [ Wed Sep 06, 2017 6:05 am ]
Post subject:  Re: Wordpress Pagination Links - how do I modify this?

A few things. First, don't modify the WordPress core. Next time you update WP, all your changes will be lost. Write a plugin or make changes at the theme level. If you're using a third-party theme, create a sub-theme and make the changes there so you can update your theme later.

To the crux of the matter. That function you posted doesn't retrieve comments, it simply creates the pagination links for comments already retrieved. Comments themselves are retrieved by . I haven't worked with WordPress in a couple of years, so I could be wrong, but I'm not seeing any obvious way to exclude empty comments. I'm kind of surprised that isn't default behaviour. Does it display empty comments even when you aren't logged in?

In any event, wp_list_comments does accept an array of comment objects as its second parameter, so you could retrieve the defaults, use array_filter or similar to filter out the empty comments, and then pass the result back to wp_list_comments. Barring that, you may need to create your own methods to retrieve and paginate over your comments. Take a look at for ideas.

Author:  simonmlewis [ Wed Sep 06, 2017 6:20 am ]
Post subject:  Re: Wordpress Pagination Links - how do I modify this?

I don't know about these queries, but yes I can see what you mean, as there is no actual query on this file.
On the page you sent, "Other Simple Comment Restrictions", this is I think where it is trying to guide to do it.
Syntax: [ Download ] [ Hide ]
Using these parameters we could list a custom comment type which contains the term "kazoo".

Syntax: [ Download ] [ Hide ]
$args = array(
    'type' => 'review',
    'search' => 'kazoo'
);
$comments_query = new WP_Comment_Query;
$comments = $comments_query->query( $args );

So how could you use this, but not to say where reviews is on "kazoo", but where comment_content is not empty? And how to do get that into the query?

That's what I am trying to learn. Oddly, it is only for this one website, because of the import we did. But it's important, as we get so many reviews, we are at the moment, only showing 30 (disabling the pagination via CSS for now).

Author:  Celauran [ Wed Sep 06, 2017 6:58 am ]
Post subject:  Re: Wordpress Pagination Links - how do I modify this?

If these are simply due to an import, would it not be easier to simply mark them as unapproved, or to delete them altogether?

Author:  simonmlewis [ Wed Sep 06, 2017 7:05 am ]
Post subject:  Re: Wordpress Pagination Links - how do I modify this?

No. I wish we could. We imported over 5,000 star reviews from a non-WP site. To do that, and keep the reviews schema, they were imported into Reviews but as they were just ratings, they had no 'comments'.

At the top of the page we have all the star reviews as an average. And in the Reviews tab, we show only reviews where it has something in comment_content, but the pagination still shows ALL the page numbers for every review for that product/post, no matter what is in that field.... hence trying to fix pagination.

Author:  simonmlewis [ Wed Sep 13, 2017 4:38 am ]
Post subject:  Re: Wordpress Pagination Links - how do I modify this?




Found these two pages. The query itself must be somewhere, in order to extract the info. I'm told that these things are edited via Hooks and Actions, but that this query doesn't have those.

I suppose it's because usually no one needs to edit it. But we need to.

It would even be in the basic Wordpress setup for reviews on Posts. Just need to figure out how to write a little query where comment_content is not empty, and put that into the query. But with WP queries I am stumped.
If it was my custom coded website, it would be easy.

Author:  Celauran [ Wed Sep 13, 2017 4:53 am ]
Post subject:  Re: Wordpress Pagination Links - how do I modify this?


Author:  simonmlewis [ Wed Sep 13, 2017 5:06 am ]
Post subject:  Re: Wordpress Pagination Links - how do I modify this?


Author:  Celauran [ Wed Sep 13, 2017 5:36 am ]
Post subject:  Re: Wordpress Pagination Links - how do I modify this?


Author:  simonmlewis [ Wed Sep 13, 2017 5:53 am ]
Post subject:  Re: Wordpress Pagination Links - how do I modify this?

Ok I can see how arrays work, and the different types. Where you can take an array, create a function with an added part to it, then merge them together.
What I don't yet see if how I can say in the array of things it is looking for in the default arg, where comment_content is empty.

In the default arg, a portion of it is this:
Syntax: [ Download ] [ Hide ]
'page'              => '',

Is the => a way of saying "equals"?
Such as "page = 'fred'"?

So could you do something a bit like this:
Syntax: [ Download ] [ Hide ]
<?php wp_list_comments( array( 'comment_content' != '' ) ); ?>

Author:  Celauran [ Wed Sep 13, 2017 6:20 am ]
Post subject:  Re: Wordpress Pagination Links - how do I modify this?


Author:  simonmlewis [ Wed Sep 13, 2017 6:31 am ]
Post subject:  Re: Wordpress Pagination Links - how do I modify this?

Thanks for confirmation.
I still don't see where you state where something is *NOT* something.
Where color is NOT red.
Where fieldname is NOT empty.
Where comment_content != ''.

Even though you cannot do that, surely you have to somehow tell it in the arg, where a field is not empty. That's the start of this puzzle for me. I See lots where field => 'red'. but not where field != 'red'.

Author:  simonmlewis [ Wed Sep 13, 2017 6:52 am ]
Post subject:  Re: Wordpress Pagination Links - how do I modify this?

Taking a step backward a little.
First I need to get into the function for list comments.

Syntax: [ Download ] [ Hide ]
wp_list_comments( $args, $comments );

This is the array in it's Arguments.
Syntax: [ Download ] [ Hide ]
$args = array(
        'walker'            => null,
        'max_depth'         => '',
        'style'             => 'ul',
        'callback'          => null,
        'end-callback'      => null,
        'type'              => 'all',
        'reply_text'        => 'Reply',
        'page'              => '',
        'per_page'          => '',
        'avatar_size'       => 32,
        'reverse_top_level' => null,
        'reverse_children'  => '',
        'format'            => 'html5', // or 'xhtml' if no 'HTML5' theme support
        'short_ping'        => false,   // @since 3.6
        'echo'              => true     // boolean, default is true

So I need to add_array to this.

Syntax: [ Download ] [ Hide ]
if(has_filter('wp_list_comments')) {
                $args = apply_filters('wp_list_comments', $args);
        }


Then this?
Syntax: [ Download ] [ Hide ]
function wp_list_comments_remove_blanks($args) {
        // the $args parameter is an array of arguments for  wp_list_comments() function
 
$additional_arg = array(
                'comment_content'  != '',
        );
 
        // combine the two arrays
        $arg = array_merge($additional_arg, $arg);
        return $arg;
}
add_filter('wp_list_comments', 'wp_list_comments_remove_blanks');


Is this getting toward it ?

Author:  Celauran [ Wed Sep 13, 2017 6:53 am ]
Post subject:  Re: Wordpress Pagination Links - how do I modify this?

Go back and look at my array_filter example. That's where you'd do it, inside the filter function you defined.

Author:  Celauran [ Wed Sep 13, 2017 7:04 am ]
Post subject:  Re: Wordpress Pagination Links - how do I modify this?

I'm pretty sure you want to hook into wp_list_comments_args. On my phone on the subway, so hard for me to dig into the code, but that's where I'd start. I'll look further tonight if you haven't resolved it.

Page 1 of 8 All times are UTC - 5 hours
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/