Skip to content

Instantly share code, notes, and snippets.

@ville6000
Created April 24, 2018 18:55
Show Gist options
  • Save ville6000/cc650893da3479dd0e0f68fc83e655d2 to your computer and use it in GitHub Desktop.
Save ville6000/cc650893da3479dd0e0f68fc83e655d2 to your computer and use it in GitHub Desktop.
Load WordPress + Polylang from outside
<?php
ini_set( 'memory_limit', '512M' );
$_SERVER['REQUEST_METHOD'] = 'GET';
$_SERVER['HTTP_HOST'] = 'siteurl.com';
define( 'USE_THEMES', false );
if ( file_exists( getenv( 'HOME' ) . '/public_html/wp-load.php' ) ) {
require_once getenv( 'HOME' ) . '/public_html/wp-load.php';
require_once getenv( 'HOME' ) . '/public_html/wp-content/plugins/polylang-pro/polylang.php';
} elseif ( file_exists( '/var/www/html/wp-load.php' ) ) {
require_once '/var/www/html/wp-load.php';
require_once '/var/www/html/wp-content/plugins/polylang-pro/polylang.php';
} else {
print "WordPress not found\n";
exit;
}
// Polylang needs plugins loaded action to work
add_action( 'plugins_loaded', function () {
$the_query = new WP_Query( [
'post_type' => 'any',
'posts_per_page' => - 1,
'no_found_rows' => true,
'lang' => '',
] );
if ( ! $the_query->have_posts() ) {
echo "No results";
exit;
}
while ( $the_query->have_posts() ) {
$the_query->the_post();
// Do magic.
if ( have_rows( 'content' ) ) {
while ( have_rows( 'content' ) ) {
the_row();
if ( 'my_layout_name' === get_row_layout() ) {
// Do more magic.
}
}
}
}
} );
do_action( 'plugins_loaded' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment