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

By default I can create feed for questions or for question's answers (without full question content).

I've found that I can change feed output in /qa-include/qa-feed.php

There is a function called qa_feed_load_ifcategory(), but despite of my poor php skills I figured out that it can either output question itself or the answer. All my tries of merging them together finished without any luck.

This is basic illustration of what I want to get in my feed:

1) Question 1 title
Question 1 content
Question 1 answer 1
Question 1 answer 2
Question 1 answer 3
2) Question 2 title
Question 2 content
Question 2 answer 1
Question 2 answer 2
Question 2 answer 3


When last parameter is passed to qa_feed_load_ifcategory(), which is $questionselectspec, the full question content is pushed away. Instead answer is added. I want to have them both.

Ofcourse, I could make some kind of workaround with my own code, but I don't want to do any crutches whith horrible piece of shit-like code.

Is there a way to achieve this through Q2A standard methods?

Q2A version: 1.8.3
If you do a MySQL query and display the results in XML format (instead of regular HTML format) , then you have a feed.

A normal RSS feed format contains such information like <title>, <link>, <pubDate>, <description>.

I'm not sure what your real purpose of feed modification is. But I guess you may want to display it in your Wordpress installtion.

So you have to put all the answers and comments and stuffs in to <description> tags.

Because your ideas will include extra variables like the answers content, answer postid,... or maybe you want to display author names and avatars too, you may not achieve this merely editing a few lines in core files. You have to write layout to display all these things.
edited by
What I'm trying to do is to add my website to Yandex Turbo Pages (the same as Google AMP, but for Yandex).

And they need special xml feed for this.

But all I can do now is feed them with trimmed content in xml, but rss feed in this situation has to represent the same content, as the normal website page.

1 Answer

0 votes

I didn't want to do it, but I had to radically change /qa-include/qa-feed.php code.

There are two functions in /qa-include/app/posts.php, which are:

  • qa_post_get_full() - gets the full question content by its id;
  • qa_post_get_question_answers() - gets all answers by the question id.
These functions are already available in qa-feed.php.
The only thing left unsolved is how to load more than 50 questions without performance issues.
Sitemap or Feed? Does Yandex require a 3000-question RSS feed? Anyway, you don't need to modify the core file. You can make a plugin. Q2A feed is actually a plugin.
edited by
Thank you for reply.

I need xml feed, not sitemap. And yes, Yandex needs everything. If you have 10.000 articles - load them all. However, there is a limit of 1000 items per one feed, so in that case I will need 10 separate feeds.

I can also use their API to load pages, bypassing xml, but didn't figure out yet how to do it. There will be more to do, because feed already contain all questions and answers, in case of API I will need to hang up an event for question creation, answer, comment and edit of any of them. This is tricky for me now, don't have enough knowledge, but maybe this will be the best approach.

Anyway, all of what I'm doing here is just my first test attempt, still in search of the best way.

I understand that it's not a good idea to modify core files, when I will figure out how to achieve this through my own plugin - will do so.

Currently I have 240 questions. In qa-feed.php I've changed $count variable from:

$count = qa_opt('feed_number_items');


$count = 500;

But it loads only 66 items in my feed. Why?
The $count variable is part of the function qa_db_qs_selectspec


It will be recalculated as

$count = isset($count) ? min((int)$count, QA_DB_RETRIEVE_QS_AS) : QA_DB_RETRIEVE_QS_AS;

It'll be the minimum of $count and  QA_DB_RETRIEVE_QS_AS, which can be found in


By the way, I won't understand why 66? It is expected be 50 in my thought.
I don't know why 66. I've printed count($questions) in my xml output from qa-feed.php and it gave me 66.

Ok, it's getting deeper into more core files, so I'll better dig into separate plugin.

Thank you for your help!
By the way, is there a function to get all questions ids? I already know qa_post_get_full() function to get specific question content, but it needs an id.

So what would be the the best practice to retrieve all questions? Or I can query DB directly?
edited by
$questions is actually an array of postids through a sophisticated function named function qa_db_qs_selectspec.


$questions = qa_db_read_all_assoc(qa_db_query_sub('SELECT postid FROM ^posts WHERE `type`="Q"  '));
will get an array of 240 postids which are questions (not answers or comments).

I believe this is not a method for submitting Yandex Rss feed.

You may submit this only ONCE, so Yandex will pick up all the information and upload into its CDN server.

In the future you may only limit the number of feeds to 3 - 10 depending on how many new questions a day your site produce, and how regular Yandex bot picks up Rss feeds.

$questions = qa_db_read_all_assoc(qa_db_query_sub('SELECT postid FROM ^posts WHERE `type`="Q" ORDER  BY created DESC  LIMIT  10  '));

Or you now chop your ^posts table into percentiles and create separate feeds for each.


$questions = qa_db_read_all_assoc(qa_db_query_sub('SELECT postid FROM ^posts WHERE `type`="Q" AND `postid` BETWEEN 30 AND 60  '));

Correct all my syntax errors, as I'm not a coder.
Why don't you try to create a simple page module plugin that outputs XML format?

It is much easier to do than trying to modify core files.

Sitemap plugin is a good example.

Thank you one more time! ))

I'll look onto this plugin and take it as starting point.

>>> "I believe this is not a method for submitting Yandex Rss feed."

But it is. Turbo pages are served through Yandex servers, so I need to "upload" my content there. So there are two ways: xml feed or API. In case of xml, Yandex will load my feed every hour to find any changes.
bigboy, I also struggle with this problem that I just did not try it, nothing happens. If you can find how to solve the problem, please share the solution. If I find it, I'll write it too.
I'll write a plugin later, if I'll have time.

I can show you how I did it for now, but If you're not a programmer you will struggle a lot. But, you can try.

This example below IS NOT THE RIGHT SOLUTION and a really bad practice. It does not completely cover the issue and changes core files, which must to be avoided, so make backups in case something will go wrong. It's not something I would ever recommend doing. It is done only in test purposes, I'm still learning PHP and Q2A as well.

Go to /qa-include/qa-feed.php file.

Inside foreach ($questions as $question) section, approximately on 405 line add:

    $qcontent = qa_post_get_full($question['postid']);
    $acontent =  qa_post_get_question_answers($question['postid']);

Now, $qcontent variable contains all question data, while $acontent - holds all answers on particular question.

Then you have to comment every $lines variable and also comment this line:

//echo implode("\n", $lines);

This has to be done, because by default Q2A is printing feeds in a way Yandex Turbo will not understand. So you have to rewrite the output of qa-feed.php.

In order to debug you can print our arrays like this:

You will see everything inside those arrays and will be able to print them as Yandex expects - https://yandex.ru/dev/turbo/doc/rss/example-docpage/
Thanks, I'll try
And be aware of the problem, that standard feed will provide no more than 50 questions, this number is hardcoded in Q2A core files.

So wee need to write a plugin in order to do it right way.