Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+3 votes
364 views
in Q2A Core by

Hello, my site is a place for questioning experts, so every question has one answer only.

How can I modify schema so that the answer directly becomes the best and chosen answer without choosing it, but rather directly.

In other words, I found that the answer appears on the basis that it is a suggested answer on schema and I want to modify it so that the answer is accepted.”

</form>
</div> <!-- END qa-a-form -->
</div>
<div class="qa-part-a-list">
<h2 id="a_list_title"><span itemprop="answerCount">1</span> الجواب</h2>
<div class="qa-a-list" id="a_list">
<div class="qa-a-list-item " id="a595" itemprop="suggestedAnswer" itemscope itemtype="https://schema.org/Answer">
<form method="post" action="../446">
<input name="code" type="hidden" value="1-1626840019-5fc213705d7e15b45913376febb6b3c074b7220d">
</form>

by
Why not make all answers best then?
by
With editing code (i want that) or with choosing every question?
by
Ideally you need an even module which listens to a_post event and then select that as best.

1 Answer

+1 vote
by
selected by
 
Best answer

How can I modify schema so that the answer directly becomes the best and chosen answer without choosing it

So you want the schema to return the answer as if it was chosen, even if it wasn't. This is an odd request, but here it goes :)

1. Edit your qa-theme/<your-theme>/qa-theme.php file

2. Add or merge this function:

public function initialize() {
    parent::initialize();
    if ($this->template === 'question' && !empty($this->content['a_list']['as'])) {
        $this->content['a_list']['as'][0]['tags'] = str_replace('itemprop="suggestedAnswer"', 'itemprop="suggestedAnswer acceptedAnswer"', $this->content['a_list']['as'][0]['tags']);
    }
}

Note I'm just turning into accepted the first answer only, as a failsafe.

by
+1
Thanks a lot, I have only one answer on each question.
I will try it
by
Thanks a lot
This is what I was looking for

Welcome to the Q&A site for Question2Answer.

If you have a question about Q2A, please ask here, in English.

To report a bug, please create a new issue on Github or ask a question here with the bug tag.

If you just want to try Q2A, please use the demo site.

Categories

...