This is the technical support forum for WPML - the multilingual WordPress plugin.

Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.

Tagged: 

This topic contains 1 reply, has 2 voices.

Last updated by Shekhar Bhandari 4 months, 2 weeks ago.

Assigned support staff: Shekhar Bhandari.

Author Posts
June 6, 2019 at 3:54 pm #3970707

ondrejP-2

I am connecting to another WordPress instance (using same database but different table prefix) from my main WordPress site. My main wordpress site has WPML plugin activated but second site has not. I am using following code:

<?php
global $wpdb;
$wpdb_backup = $wpdb;
$wpdb = new wpdb('xxx','yyy','zzz','localhost');
$wpdb->set_prefix('blog_');

$args = array(
'post_type' => 'post',
'posts_per_page' => 3,
'post_status' => 'publish',
'orderby' => 'date',
'order' => 'DESC',
);

$query = new WP_Query($args);

if($query->have_posts()) {
while($query->have_posts()) {

$query->the_post();
// do stuff here
}
}

wp_reset_query();
$wpdb = $wpdb_backup;
?>

The problem is that new connection is not looking directly to blog_posts table but is trying to find post through WPML table causing this problem:

WordPress database error: [Table 'd54525_720.blog_icl_translations' doesn't exist]

Is there any way to disable WPML and enable it after query or change WP query to ignore WPML functions? Thanks for help.

June 7, 2019 at 3:34 am #3973775

Shekhar Bhandari
Supporter

Languages: English (English )

Timezone: Asia/Kathmandu (GMT+05:45)

Hello there,

Welcome to WPML support. I'd be assisting you further on this issue.

It seems you are trying to run the code in the secondary languages and the default language of the posts from another site is not matching, creating the issue, you can switch language and retrieve the posts in the correct language to see if it helps.

https://wpml.org/documentation/support/wpml-coding-api/wpml-hooks-reference/#hook-662213

Anyway, custom programming help is beyond the scope of our support.

At this point, I would suggest you consider contacting one of our certified partners from this link: http://wpml.org/documentation/support/wpml-contractors/

Before doing so please have a look also here:
http://wpml.org/documentation/support/wpml-contractors/guidelines-for-people-looking-for-consulting-help/

You will get the custom assistance you need to get on with your project.

Thanks