Created
January 9, 2020 19:44
-
-
Save k1sul1/eb04e89b4c3a8ee3404e0a33d8eac0cf to your computer and use it in GitHub Desktop.
Get all translations of post content from a value translated with qtranslate-x
This file contains 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 | |
$post = $GLOBALS['post']; | |
$wpdb = $GLOBALS['wpdb']; | |
// :trollface: | |
// qtranslate is not a very nice tool | |
$id = (int) $post->ID; // No injections here | |
$raw = $wpdb->get_var("SELECT post_content from $wpdb->posts WHERE ID = $id"); | |
$extractor = function($lang = 'fi') use ($raw) { | |
static $parsed; | |
if (!$parsed) { | |
$parts = explode('[:', $raw); | |
foreach ($parts as $k => $part) { | |
if ($k === 0) { | |
continue; | |
} | |
$k = substr($part, 0, 2); | |
if ($k === ']') { | |
continue; | |
} | |
$text = substr($part, 3, strlen($part)); | |
$parsed[$k] = $text; | |
} | |
} | |
return $parsed[$lang]; | |
}; | |
$fi = $extractor('fi'); | |
$en = $extractor('en'); | |
$sv = $extractor('sv'); | |
var_dump([$fi, $en, $sv]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment