Wrong comments number when post displayed in block

Posted in: Newspaper
Post count: 9

We are using Newspaper 10.4, tagDiv Composer 2.8.

We have integrated other social platform with wordpress. Integration plugin hooks in with new comment number calculation method with:
add_filter( ‘get_comments_number’, array( $someobject, ‘somemethod’ ) );

Logic is simple: sum of WP comments and other social media platform comments (via APIs).

Newspaper correctly displays comments number when in the_loop (home page for example) or in the_post (single post).

But when the home page section is built using block (template: global header template) it is only showing number of WP comments (so doesnt count comments from other platform).

Looks like the hook is not working in this block?

Please advise how can this be fixed or what should be checked?

Post count: 27744

Hello,

Unfortunately, we don’t know what the problem would be, because we haven’t tested that hook and we don’t know how it works.

Thank you for understanding!

Post count: 9

It is standard WordPress hook for get_comments_number() function.

Function:
https://developer.wordpress.org/reference/functions/get_comments_number/.

Hook:
https://developer.wordpress.org/reference/hooks/get_comments_number/

It looks like the Newspaper theme is not initializing something when creating home page with blocks?

If this was not tested before, could you please test it now?

  • This reply was modified 5 years by def.
Post count: 18283

Hello !

Can you send us some screenshots with the steps you took in order to see how did you inserted this hook and see what can be done about it ?

Thank you !

Post count: 9

Hello @Vlad S

I am not php/wp developer, but I think the simplest test would be to do a plugin like this:

/*
Plugin Name: Just a test
Plugin URI: justatest.org
Description: Just a test
Version: 1.0
Author: Just a test
Author URI: justatest.org
License: Just a test
License URI: justatest.org
*/

function return_always_123( $count, $post_id ) {
return 123;
}

add_filter( 'get_comments_number', 'return_always_123' );

?>

Install and activate it.

Now every post (in the_post or the_loop) will have 123 comments, regardless of what is stored in wp tables (so filter is applied).

The posts listed in the block (we have home page parts with the_loop but blocks as well) sections will have whatever-is-real-comments-number (so filter is not applied).

  • This reply was modified 5 years by def.
  • This reply was modified 5 years by def.
Post count: 27744

Hello,

We also tested this code, and indeed it does not apply on blocks but only on posts loop. and its behaviour is like a plugin.
The blocks from our theme are custom elements created by our developers and to apply the code from the created plugin new implementations or adjustments are needed depending on how the code should work (a developer is needed), theme support is only for guidance and theme settings.
If you really want to change this you can contact our custom work team here: https://tagdiv.com/premium-customization-services/

Thank you!

Post count: 9

So basically blocks from your theme are not using any official wordpress hooks and are fully custom code? That means many plugins may not work properly.

Ok, then developer is needed (or maybe you plan to fix it in next release?). If not we will fix it on our own (for our own problem, comments number, it should be one additional line of code to apply filters). But fixing it just for our site – while other may have similar problem – is not good for others as for us (theme upgrade may delete our code).

  • This reply was modified 5 years by def.
Post count: 27744

Hello,

The standard elements can be used with hooks, but the cloud templates have a different custom code.

Thank you!

Viewing 8 posts - 1 through 8 (of 8 total)
You must be logged in to reply to this topic.