-
cubanitomsn
Hi GP Team,
I am using GP Premium with Polylang (free). I have each page in two languages (Spanish and English) and several of them with comments. I need, for example, page A in English to show the mixed comments on page A in Spanish and vice versa. I have already achieved it using the following code with Elementor Hook<ol class="comment-list"> <?php $comments = get_comments(array( 'post__in' => array( 2052, 5266 ), 'status' => 'approve' )); //Display the list of comments wp_list_comments(array( 'reverse_top_level' => false ), $comments); ?> </ol>
Where 2052, 5266 are the IDs of the page version of one and another language
With this code I achieve that each page correctly shows the mixed comments of both associated pages, but also duplicates at the end the comments placed on it. I suppose that the solution is to eliminate the order that by default makes it possible to view the comments of each page, and only those of my functions remain, maybe using something like “remove_filter…” or “remove_function…”, but I don’t know how to do it, any help will be welcome.
I’m developing the site on localhost
-
Hi there,
I’m not sure I fully understand your question, are you looking to remove the default comment for the 2 specific pages?
Let me know 🙂
-
cubanitomsn
Hi Ying,
What I need is to remove the default list comment and show my list comments, in order to not repeat comments. Now it´s show me the list of comments of both pages, that’s OK; and at the end the list of comments of this page (the default way), I want to remove the last one list. (But remaining the comments form on both page)
-
Do you only want to remove the default comments on the two pages or all pages?
And are they pages or posts?
Let me know!
-
cubanitomsn
The webssite for the momment has in total around 20 pages, it is under development; and some Custom post type (I used CPT UI for it). I need it for some of the pages and for an specific custom post type with comments allowed named “houses” (with several post). Im Ok using conditionals and so on.
-
You can try using this filter and add your conditions to it:
add_action( 'wp', 'remove_generatepress_comments' ); function remove_generatepress_comments() { remove_action( 'generate_after_do_template_part', 'generate_do_comments_template', 15 ); }
-
cubanitomsn
Sorry does not work,
Dont know if it have any sense but maybe what I need to remove is the using of the <wp_list_comments> function, using remove_action and replace it with mine, not sure the hook that contain that function.
-
Sorry does not work,
Hum…in that case, take a look at the GP’s
comment.php
file, you might need to use a child theme and take a copy of the file and modify the comment list highlighted:
https://github.com/tomusborne/generatepress/blob/master/comments.php#L90-L105 -
cubanitomsn
HI
Following Ying suggestion I have copied and modified commet.php in my child theme and it works fine with the pages. Here the conditional code based used
if ( is_page( array( 2052, 5266 ) )) { //Pages IDs to use in 'post__in' => array(...) ?> <ol class="comment-list"> <?php //Gather comments for a specific page/post $comments = get_comments(array( 'post__in' => array( 2052, 5266 ), 'status' => 'approve' //Change this to the type of comments to be displayed )); //Display the list of comments wp_list_comments(array( //'per_page' => 20, //Allow comment pagination 'reverse_top_level' => false ), $comments); ?> </ol> <?php }
The problem I have is that there are many custom post types to process and I can’t find a way to get the pair of IDs dynamically (the pages were only 4, so it was easy to obtain their IDs).
In other words, I would have to get the ID of the CPT that is displayed and obtain its translated partner from it. I know that polylang has a function that could help: pll_get_post_translations( $post_id ); but my knowledge does not allow me to process this array.
Any help would be welcome, although I think that this would already be a matter to be discussed with the polylang plugin developers
-
There should be a relationship between the original CPT and the translated CPT.
Hope Polylang’s support can help with a dynamic solution 🙂
-
cubanitomsn
Thaks for your help. I will mark it as resolved
-
You are welcome 🙂
- You must be logged in to reply to this topic.