corcel / corcel

Use WordPress backend with Laravel or any PHP application

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Help getting posts per language

zehfred opened this issue · comments

Hi,

I'm trying to query a multi language (it uses the Polylang plugin) WordPress installation and save entries into a Statamic site, but have hit a roadblock. Admittedly I'm not very proficient with PHP, so please bear with me.

I can get posts per language like this:

$posts = Post::type('destination')->taxonomy('language', 'en)->published()->orderBy('post_title')->get();

It returns all the posts that have the language set as English. All good here. My problem is that I want to create entries in Statamic per locale (it's a multi-site installation) and I need to query all the posts first and then relate every entry with the origin (locale 'en').

So I need to query the post that has language set as en then find out the related posts per language so I can create an id for the original English posts and tell the translated content that one is the original.

If I do something like this:

$locales = array('en', 'es', 'fr', 'de', 'pt');
$posts = Post::type('destination')->published()->orderBy('post_title')->get();

foreach ($locales as $locale) {
    $posts = $posts->taxonomy('language', $locale);
    return $posts;
}

It returns:

BadMethodCallException 
Method Illuminate\Database\Eloquent\Collection::taxonomy does not exist.

Can someone please point me in the right direction? Thanks.

Figured it out.