You can try:
/**
* Change the posts table name from 'wp_posts' to 'wp_my_posts'
* Version #2 - The 'muplugins_loaded' action
*/
add_action( 'muplugins_loaded', function(){
global $wpdb;
$wpdb->posts = 'my_posts';
});
where muplugins_loaded
is the earliest action hook available.
You can also hijack the query
filter, that’s fired before the muplugins_loaded
action:
/**
* Change the posts table name from 'wp_posts' to 'wp_my_posts'
* Version #3 - Hijack the 'query' filter, the first time it's fired.
*/
add_filter( 'query', 'b2e_change_table_name' );
function b2e_change_table_name( $query ){
remove_filter( current_filter(), __FUNCTION__ );
global $wpdb;
$wpdb->posts = 'my_posts';
return $query;
}
It might also be worth trying this in the global scope:
/**
* Change the posts table name from 'wp_posts' to 'wp_my_posts'
* Version #4 - The global scope
*/
global $wpdb;
$wpdb->posts = 'my_posts';
before any action/filters are fired.
Does this work for you?