1. Go to this page and download the library: Download peakhmr/wpml library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
peakhmr / wpml example snippets
// All published posts
$posts = Post::published()->get();
$posts = Post::status('publish')->get();
// A specific post
$post = Post::find(31);
echo $post->post_title;
// Filter by meta/custom field
$posts = Post::published()->hasMeta('field')->get();
$posts = Post::hasMeta('acf')->get();
// Find a page by slug
$page = Page::slug('about')->first(); // OR
$page = Post::type('page')->slug('about')->first();
echo $page->post_title;
// Find a translation collection by post id or slug
$post = Post::find(31)->translation(); \\ OR
$post = Post::slug('about')->translation();
\\ Result
TranslationCollection {#1855 ▼
#changedKeys: []
#items: array:2 [▼
0 => Translation {
#original: array:6 [▼
"translation_id" => 38
"element_type" => "post_page"
"element_id" => 31
"trid" => 19
"language_code" => "en"
"source_language_code" => null
]
}
1 => Translation {#1853 ▶}
]
}
// Find a translation collection by post id or slug
$lang = 'en'; \\ OR
$lang = config('app.locale');
$post = Post::slug('about')->translate($lang);
\\ Result
Page {#1847 ▼
#postType: "page"
#original: array:23 [▼
"ID" => 6
"post_author" => 1
"post_date" => "2017-06-12 04:49:06"
"post_date_gmt" => "2017-06-12 04:49:06"
"post_content" => "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod."
"post_title" => "Lorem ipsum dolor sit amet"
...
]
}
function acf_admin_script()
{
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.