Comments (5)
@digg I answered you about the PR and it's crystal clear as I was trying to do the same but failed with wp menu assign
( I didn't know about the runcommand
magic ).
About wp pll post create
, I don't know if it's possible/advised to use complex arguments ( like JSON for instance ). For now what I'm doing is :
wp pll post create fr --post_type=page --post_title='Accueil' --post_status=publish --porcelain # returns 3
wp pll post create en --post_type=page --post_title='Home' --post_status=publish --porcelain # returns 4
wp pll post bind '{ "en": 3, "fr": 4 }'
with :
public function bind( $args, $assoc_args ) {
$bindings = json_decode( $args[0], true );
$this->api->save_post_translations( $bindings );
$this->cli->success( 'Posts bound.' );
}
public function create( $args, $assoc_args ) {
list( $language ) = $args;
$languages = $this->api->languages_list();
$default_language = $this->api->default_language();
if ( ! $this->api->is_translated_post_type( $this->cli->flag( $assoc_args, 'post_type' ) ) ) {
$this->cli->error( 'Polylang does not manage languages and translations for this post type.' );
}
$porcelain = isset( $assoc_args['porcelain'] );
$assoc_args['porcelain'] = true;
ob_start();
$this->cli->command( array( 'post', 'create' ), $assoc_args );
$post_id = ob_get_clean();
$this->api->set_post_language( $post_id, $language );
$porcelain ? $this->cli->log( $post_id ) : $this->cli->success( sprintf( 'Created post %s.', $post_id ) );
}
The code is simple as it's just a proof of concept ( missing some error handling, etc ).
And the use could be easily simplified as :
wp pll post create --post_type=page --post_title='{ "fr": "Accueil", "en": "Home"}' --post_status=publish --porcelain
But I don't know if it's best practice, as I mentioned above, to use JSON arg in WP-CLI philosophy.
Perhaps something like this instead :
wp pll post create --post_type=page --post_title='Accueil' --post_title_en='Home' --post-status=publish --porcelain
from polylang-cli.
@gbouteiller An important idea behind this package is that CRUD commands perform batch operations, e.g. wp post delete
deletes a post, while wp pll post delete
deletes a post and all its translations.
So I guess the same logic would have to be applied to wp pll post create
, which would create a post and its "translations". More fine-grained control would be obtained by passing some extra params, e.g. wp pll post create 34 de
would create a German translation for the post with ID 34.
Automating a multilingual setup is one of the main reasons this package exists. The use case you're describing (creating and setting home pages) is definitely something I would like to see polylang-cli be able to do. With a little creativity however (and the latest master) I think this is already possible:
$ wp option update show_on_front page
$ wp pll post generate --post_type=page --format=ids --count=1 | xargs -n1 -I {} sh -c 'wp option update page_on_front {}'
from polylang-cli.
At first, I was just thinking about something similar to polylang : a translation is a post, so wp pll post create
is for creating only one translation ( I've forked your project to do something like that ). But I understand what you mean and it makes sense in the CRUD logic. So, how would you create a page with title and content in three different languages for example?
About your example, wp post generate
doesn't give you the possibility to set titles and translations, does it? For now, I'm using the fork to generate translated pages and link them together and after that I'm able to use wp option update page_on_front
.
Another question on my mind related to an issue I posted on polylang is about menu location assignments, do you want to discuss it here or do I open another issue for that?
from polylang-cli.
Unfortunately, wp post generate
allows only to set the post content, title is automatically generated based on the post type object's singular_name
label.
So, how would you create a page with title and content in three different languages for example?
I'm not really sure, but very much open to suggestions :) Where would the input come from?
Right now I'm thinking to use wp create post
internally and duplicate the post object to the other languages.
Another question on my mind related to an issue I posted on polylang is about menu location assignments, do you want to discuss it here or do I open another issue for that?
Yes, it would be better to discuss this in another ticket.
from polylang-cli.
@gbouteiller I just pushed a wp pll menu create
command at #48, we can discuss it there if you like
from polylang-cli.
Related Issues (20)
- add `wp pll post update` subcommand
- add `wp pll term list` subcommand
- support WooCommerce product duplication
- Command to set the license for polylang pro HOT 3
- Cannot be installed with wp-cli 2.2.0 out of the box HOT 12
- When the package is activated WP CLI is not assigning posts to the default language
- add script to generate docs
- remove behat featurecontext customization
- add `wp pll widget list` subcommand
- Document alternative solution HOT 5
- fix wp pll option sync/unsync
- Undefined index: hook_suffix in `wp pll string list` HOT 1
- fix `wp pll doctor language`
- update package framework, require WP-CLI 1.3.0
- PHP Notice: Undefined index: class in ./vendor/diggy/polylang-cli/src/Api/Api.php on line 46
- add `wp pll menu item` subcommand
- add `wp pll menu list` subcommand
- add `wp pll menu delete` subcommand
- add `wp pll term duplicate` subcommand
- add `wp pll post duplicate` subcommand
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from polylang-cli.