-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FEATURES : wp pll post create, wp pll post bind #45
Comments
@gbouteiller An important idea behind this package is that CRUD commands perform batch operations, e.g. So I guess the same logic would have to be applied to 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:
|
At first, I was just thinking about something similar to polylang : a translation is a post, so |
Unfortunately,
I'm not really sure, but very much open to suggestions :) Where would the input come from? Right now I'm thinking to use
Yes, it would be better to discuss this in another ticket. |
@gbouteiller I just pushed a |
@digg I answered you about the PR and it's crystal clear as I was trying to do the same but failed with 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 ). 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. wp pll post create --post_type=page --post_title='Accueil' --post_title_en='Home' --post-status=publish --porcelain |
Create a new post and its translations. Closes #45
Hello @diggy,
Won't it be a good idea to offer the possibility to create posts in a specific language and link them?
wp pll post create
would look likewp post create
but with the ability to pass the language.wp pll post bind
would mimicpll_save_post_translations
to bind posts created in 1.My use case is to generate for every new website a basic structure with some pages ( Home, Contact, Blog, ... ) that are available in English and French by default and then add Home as frontpage with
wp option update page_on_front
. This currently doesn't work because, in order to update the option, polylang checks that the given id is translated and bound to a translation in every language.The text was updated successfully, but these errors were encountered: