PHPackages                             peakhmr/wpml - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. peakhmr/wpml

Abandoned → [jgrossi/corcel](/?search=jgrossi%2Fcorcel)ArchivedLaravel

peakhmr/wpml
============

Corcel Multilingual Plugin for WPML \[The WordPress Multilingual Plugin\]

v1.0.8(7y ago)04.3k1MITPHP

Since Jul 1Pushed 6y agoCompare

[ Source](https://github.com/socheatsok78/corcel-wpml)[ Packagist](https://packagist.org/packages/peakhmr/wpml)[ Docs](https://github.com/peakhmr/wpml)[ RSS](/packages/peakhmr-wpml/feed)WikiDiscussions master Synced today

READMEChangelog (9)Dependencies (3)Versions (13)Used By (0)

Corcel WPML
===========

[](#corcel-wpml)

> This package allows you to use Corcel WordPress plugin with The WordPress Multilingual Plugin that allow you to easily build multilingual sites and run them. It’s powerful enough for corporate sites, yet simple for blogs.

[![Travis branch](https://camo.githubusercontent.com/112c66533a244abd41cd670d88637abb00b42ed5f48e05879eee3867366bc3a6/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f736f6368656174736f6b37382f77706d6c2f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/socheatsok78/wpml)[![GitHub issues](https://camo.githubusercontent.com/69832e6346ed98dee23ceead2f85151c56974ddc5e0d79c7b048734448e33b3f/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732f736f6368656174736f6b37382f77706d6c2e7376673f7374796c653d666c61742d737175617265)](https://github.com/socheatsok78/wpml/issues)

Installation
------------

[](#installation)

> This package is still in development

To install Corcel WPML, just run the following command:

```
composer require peakhmr/wpml
```

[![Packagist](https://camo.githubusercontent.com/563fe0ca3b05be03c93d0552aedff42d11fe761ba03d3a81a27d29e61c2d4999/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7065616b686d722f77706d6c2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/peakhmr/wpml)[![GitHub release](https://camo.githubusercontent.com/afce33c76fa88312ee6a3f810d7fd74d42d64c478f2d661d281c9e600528e667/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f7065616b686d722f77706d6c2e7376673f7374796c653d666c61742d737175617265)](https://github.com/peakhmr/wpml/releases)

Usage
-----

[](#usage)

---

### Posts

[](#posts)

> Every time you see Post::method(), if you're using your own Post class (where you set the connection name), like App\\Post you should use App\\Post::method() and not Post::method(). All the examples are assuming you already know this difference.

```
// 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();
```

### Pages

[](#pages)

> Pages are like custom post types. You can use Post::type('page') or the Page class.

```
// Find a page by slug
$page = Page::slug('about')->first(); // OR
$page = Post::type('page')->slug('about')->first();
echo $page->post_title;
```

For documentation please visit [jgrossi/corcel](https://github.com/corcel/corcel#usage) for Corcel's usage and then come back here for how to use wpml plugin.

### Translations

[](#translations)

> By using the `$post` object, we can access to the translation created by WPML.

Instead of using `Corcel\Post`, we use `Wpml\Post` to Override few variables. The plugin will look for `wp_posts.ID` in `icl_translations.element_id` and return a collection of `icl_translations.trid`.

```
// 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 ▶}
  ]
}
```

### Translate Post or Page

[](#translate-post-or-page)

If you want to get the translated post object, use `translate()` scope and passing the `icl_translations.language_code` as parameter. This will return `Corcel\Post` object as expected.

```
// 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"
    ...
  ]
}
```

### Advanced Custom Field, Field Keys

[](#advanced-custom-field-field-keys)

Add the follwing PHP script to your WordPress theme's `function.php`. This script will append a button `Transfer Advanced Custom Field Accessor Keys` to the `Multilingual Content Seup` section. This action button will toggle all `_field_key` as `copy` for you.

[![Multilingual Content Seup](docs/images/multilingual_content_seup.png)](docs/images/multilingual_content_seup.png)

```
  function acf_admin_script()
  { ?>

      /**
      * Advanced Custom Field Accessor key copy tools
      */

      $(document).ready(function() {
        $('#icl_div_config #icl_mcs_details p').prepend('Transfer Advanced Custom Field Accessor Keys')
      });

      function apply_acf_accessor() {
        var table = $('#icl_div_config #icl_mcs_details table tbody');
        var expression = /^_[\d\S]+/;
        var rows = table[0].rows;

        for (var i = 0; i < rows.length; i++) {
          var element = $(rows[i]);
          var validator = $(rows[i]).find('td[id]')[0].textContent;

          if (expression.test(validator)) {
            $(element).css({
              background: 'rgba(207, 73, 68, 0.3)'
            }).find('td').css({
              color: '#333'
            });
            $(element).find('td[align] label:nth-child(2) input').prop('checked', 'checked');
          }

        }
      }
