Fixed Q&A issues detected (via Google)

cdub

Well-known member
Affected version
2.2.7
Got this:

Search Console has identified that your site is affected by 1 Q&A issues:

Top Errors

Errors can prevent your page or feature from appearing in Search results. The following errors were found on your site:

Either "acceptedAnswer" or "suggestedAnswer" should be specified
We recommend that you fix these issues when possible to enable the best experience and coverage in Google Search.

What does this mean?
 
We think we can see why this is happening and it is related to a recent change but it shouldn't affect anything.

We changed the way we count "answers" but Google assumes if you have "answers" then there should be an acceptedAnswer or a suggestedAnswer which isn't always the case.

It will be adjusted but it should be safe to ignore for now.
 
Either way, we should talk about Google.

I think they work to hope for a better internet and user experience, but all of this policies is causing a nightmare for developers to keep track of all the changes and 'features' they want.

Each day, a new e-mail with a new warning about something changed in the Search Console because some new tag was implemented, or because Core Web Vitals released a new pattern or anything like that.

Usually i ignore all warnings on Search Console, except for the critical ones, some 404 page, or server down, etc.
 
I’m not sure how anyone, apart from people at Google, knows whether this kind of stuff is harmful to your site or not. Either way, I do find myself concerned by it so I changed the two threads I was notified about from question to discussion type.
 
Everyone thinks that you get one minor error and suddenly every single thread you've ever made will disappear from Google.

It's just not how it works.

This will affect Google's ability to display the thread with the expected Q&A schema metadata. Nothing else. The errors in the relevant testers even explain that:

1631785551949.png

Search results will still appear once they are indexed:

1631785621763.png

This thread is unaffected. The only difference is the mention of the "Top answer":

1631785876424.png

The errors are safe to ignore for the moment.
 
Does anyone thing this might actually be a bad thing? I mean - if the Google likes your answer, they're going to post it within the search results. If people find the answer ON Google and don't need to visit your site - not sure how that is good for the forum owner.
Jeez, you can't type anything on a phone these days without looking it over ten times. I wish I could edit that message - it's such a grammatical disaster...
 
"Errors can prevent your page or feature from appearing in Search results. The following errors were found on your site: Either "acceptedAnswer" or "suggestedAnswer" should be specified"

It may be better to just turn this feature off altogether. With it, you risk losing ranking for that page in Google. Without it, it just gets listed like any other discussion. However, if an accepted or suggested answer is selected - that data (answer) will simply appear in Google - losing the traffic you could have earned if it were not listed there. I'm turning Q&A forums off in all my communities.
 
With it, you risk losing ranking for that page in Google
This is exactly what is currently taking place on our website.
So I am amazed at answers like this:

Do customers care that much by now?
 
It is filling the Search Console with thousands of errors quickly. However, it could be temporarily reverted by using the following extension until it is fixed/adjusted in the core application. GSC is basically expecting answerCount = 0 if there is no acceptedAnswer.
Note: I edited the code to use the proper extension class name as @Kirby explained below.
PHP:
<?php

namespace MyAddon\XF\ThreadType;

use XF\Entity\Post;
use XF\Entity\Thread;

class Question extends XFCP_Question
{
    public function getLdStructuredData(Thread $thread, Post $firstDisplayedPost, int $page, array $extraData = [])
    {
        $sd = parent::getLdStructuredData($thread, $firstDisplayedPost, $page, $extraData);
        if (!isset($sd['mainEntity']['acceptedAnswer'])) {
            $sd['mainEntity']['answerCount'] = 0;
        }
        return $sd;
    }
}
 
Last edited:
For others reading this and wanting to use your code:

For a proper extension this should be
PHP:
class Question extends XFCP_Question
 
For others reading this and wanting to use your code:

For a proper extension this should be
PHP:
class Question extends XFCP_Question
Thanks.
(XFCP_Question is just an extension hint, the real extension class is \XF\ThreadType\Question. Just FYI.)
 
(XFCP_Question is just an extension hint, the real extension class is \XF\ThreadType\Question. Just FYI.)
No ;)

The real extension class would only be XF\ThreadType\Question if there are no other classes with a lower execution order extending this class as well.
If there are other classes, the real extension class might be OtherVendor\OtherAddOn\XF\ThreadType\Question.

If your Add-on directly extends XF\ThreadType\Question you could "kill" those other extensions.

For class extensions to work properly, all extensions classes must extend XFCP_*.
 
No ;)

The real extension class would only be XF\ThreadType\Question if there are no other classes extending this class as well with a lower order.
If there are other classes, the real extension class might be OtherVnendor\OtherAddOn\XF\ThreadType\Question depending on the order.

If your Add-on directly extends XF\ThreadType\Question you would "kill" those other extensions.

For class extensions to work properly, all extensions classes must extend XFCP_*.
You are right. Very well explained.
Thanks again.
 
If I understand correctly, would you have to create a new add-on here?
Couldn't it be easier by adding some code to the "question.php"?
 
If I understand correctly, would you have to create a new add-on here?
Couldn't it be easier by adding some code to the "question.php"?
As a quick and dirty patch (that triggers consistency check errors) and if you are confident enough to not wreck the file while patching: Yes.
As a maintainable intermediate workaround: No.
 
No ;)

The real extension class would only be XF\ThreadType\Question if there are no other classes with a lower execution order extending this class as well.
If there are other classes, the real extension class might be OtherVendor\OtherAddOn\XF\ThreadType\Question.

If your Add-on directly extends XF\ThreadType\Question you could "kill" those other extensions.

For class extensions to work properly, all extensions classes must extend XFCP_*.
@Kirby - I edited my code to use the proper extension.
If I understand correctly, would you have to create a new add-on here?
Couldn't it be easier by adding some code to the "question.php"?
Personally, I wouldn’t touch the core application scripts.
 
Back
Top Bottom