• Resolved karimit

    (@karimit)


    Hi,
    I’m trying to set a default language of posts created by a plugin for questions and answers that I use.
    The only language installed in my site is Arabic. And since questions and answers has no defined language, I can’t get comments related to them because Polylang tries to filter results by language.
    When I registered the question and answer post types using the pll_get_post_types filter I was able to set their language through the admin screen. But now I’m searching for a way to set the language automatically for new posts maybe with an action, or disable filtering by language for these tow custom post types.

    Thanks in advance.

    http://ww.wp.xz.cn/plugins/polylang/

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Chouby

    (@chouby)

    disable filtering by language for these tow custom post types

    That’s the easiest. You just have to deactivate the language and translation management for these custom post types in Polylang settings. Depending on the way you wrote your pll_get_post_types filter, your post types may not appear, so if they don’t try removing your filter.

    Thread Starter karimit

    (@karimit)

    Hi Chouby,
    Thanks for your response.
    The problem was not introduced by the pll_get_post_types. I just added this filter to try change the language of a cpt from the admin screen to see if that solves the problem, and it does.
    The problem is always there whether the filter exists or not (unless if I manually change the language from the admin screen as I said) because Polylang always adds this little condition to the query :
    pll_tr.term_taxonomy_id = 4
    where 4 is the id of the term with value of “ar”.
    I hope I explained the issue well.
    Thanks again, waiting for your response 🙂

    Plugin Author Chouby

    (@chouby)

    If you don’t use the filter and you de-activate the language and translation management for your custom post type in Polylang settings then the Polylang shoud not filter your custom post type (and so not add this pll_tr.term_taxonomy_id = 4 in query)

    Thread Starter karimit

    (@karimit)

    I removed the filter and de-activated the language and translation management for my custom post types in Polylang settings (all check boxes for cpt’s are unchecked) and still Polylang filters the posts.
    Is there any other reason why this is happening, maybe some settings I must check?
    I am really sorry if I’m wasting your time, but i tried for too long to solve this on my own and I just couldn’t.

    Thread Starter karimit

    (@karimit)

    I just added the following action to functions.php, and Problem Solved:

    function update_post_language( $post_id ) {
    	$post_type = get_post_type($post_id);
    	if ($post_type == 'dwqa-question' || $post_type == 'dwqa-answer') {
    		$term = term_exists('ar', 'language');
    		if ($term !== 0 && $term !== null) {
    			wp_set_post_terms( $post_id, array ('ar'), 'language', true );
    		}
    	}
    }
    add_action( 'save_post', 'update_post_language' );

    Thanks again 🙂

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Setting default language for custom post types’ is closed to new replies.