Whenever I publish a new post on my WP site, I also create a new topic on my forums (running phpBB). I also enter the ID of the forum topic in a custom field of my WP post. It is used to output a link in the theme to the forum post when reading the post on the WP site.

Now what I want to do is to query the forum’s DB and get the number of replies from that topic and output the number of replies in my theme right next to the link.

I know that I can set up a new connection to any external DB easily by using something like this:

$mydb = new wpdb('username','password','database','localhost');

But how about the query itself? Select ‘topic_posts_approved’ from ‘phpbb_topics’ where ‘topic_id’ = ‘the corresponding WP custom field value‘.

Please help!

Read more here: query external DB and display value in theme


If you know the solution of this issue, please leave us a reply in Comment section, to update the question.

Wordpress related questions and answers: