gerlos
Forum Replies Created
-
Sorry, I’d like to help, but I’m new and don’t know where to look for logged errors. Can you tell me please where to look?
Thanks for the tip about save_post. I think I wouldn’t see the difference since I don’t plan to post periodically anything different than blog post, but it’s good to know the right way to do it.
Solved!
I’m posting here my solution for future reference and to get feedbacks from more experienced users.To recap: this should set the default language for published posts if they don’t already have any assigned language, as happens when you post from wordpress android app or send posts by email.
I just added it at the bottom of my theme’s functions.php file:
function add_polylang_language($post_id) { global $polylang; if ( !$polylang->get_post_language($post_id) ) { $polylang->set_post_language($post_id, pll_default_language()); } return $post; } add_action('publish_post', 'add_polylang_language');Did some experiments and didn’t seem to break anything, but I’d be more than happy to if anyone try it and give me some comment.
I think I found how I should do it. It seems to me I should add to my theme’s functions.php file something like this:
function add_polylang_language($post) { global $polylang; if ( !$polylang->get_post_language($post['ID']) ) { $polylang->set_post_language($post['ID'], pll_default_language()); } return $post; } add_action('save_post', 'add_polylang_language');Being this my first try, no I’m not surprised it doesn’t work. Any help?
I’ve seen that another plugin, postie, suggests a workaround here:
http://postieplugin.com/postie-polylang/This gave me a rough idea of how I could solve my problem: when a post get published, a function should check if there is a language already assigned to it, and assign it if it’s missing.
Now, since I’m new in the wordpress world, I really don’t know where to start coding this solution, any clue?