• Resolved Pierre Minik

    (@pierreminik)


    Hi,

    I have this custom post type called status which is not translated. On the author’s archive pages I want only this custom post type to be shown. How do I disable Polylang for this query? I get no results at all since I think Polylang is trying to query the current language.

    Here’s what I’ve tried.

    function loop_author_archive( $query ) {
    
    	if ( $query->is_author() && $query->is_main_query() && ! is_admin() ) {
    
    		$query->set( 'post_type', array( 'status' ) );
    
    	}
    
    }
    add_action( 'pre_get_posts', 'loop_author_archive' );

    https://www.ads-software.com/plugins/polylang/

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

    (@chouby)

    Hi!

    You should look for the query. It probably includes the query var ‘lang’ or a tax query with the ‘language’ taxonomy. You have to unset them to avoid the query being filtered by language.

    Thread Starter Pierre Minik

    (@pierreminik)

    Thanks, Chouby!

    Here’s how I fixed it:

    function loop_author_archive( $query ) {
    
    	if ( $query->is_author() && $query->is_main_query() && ! is_admin() ) {
    
    		$query->set( 'post_type', array( 'status' ) );
    
    		unset( $query->query['lang'] );
    		unset( $query->query_vars['lang'] );
    		unset( $query->tax_query->queried_terms['language']);
    
    	}
    
    }
    add_action( 'pre_get_posts', 'loop_author_archive' );
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How to disable Polylang for query’ is closed to new replies.