Created
April 24, 2018 18:55
-
-
Save ville6000/cc650893da3479dd0e0f68fc83e655d2 to your computer and use it in GitHub Desktop.
Load WordPress + Polylang from outside
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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