Web Hosting
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

WordPress fix Reply To: The case of the mysterious redirect

Discussion in 'Misc WordPress Requests' started by jlysgaard, Dec 1, 2017.

  1. jlysgaard

    Guest

    Reply To: The case of the mysterious redirect, by jlysgaard

    Thanks! There is an instance of this in my theme’s(Divi) custom_functions.php, but I’m not fluent in PHP to see if any of this should cause trouble. Does any of this jump out at you?

    add_action( 'pre_get_posts', 'et_custom_posts_per_page' );

    function et_custom_posts_per_page( $query = false ) {
    global $shortname;

    if ( is_admin() ) {
    return;
    }

    if ( ! is_a( $query, 'WP_Query' ) || ! $query->is_main_query() ) {
    return;
    }

    if ( $query->is_category ) {
    $query->set( 'posts_per_page', (int) et_get_option( $shortname . '_catnum_posts', '5' ) );
    } elseif ( $query->is_tag ) {
    $query->set( 'posts_per_page', (int) et_get_option( $shortname . '_tagnum_posts', '5' ) );
    } elseif ( $query->is_search ) {
    if ( isset( $_GET['et_searchform_submit'] ) ) {
    $postTypes = array();
    if ( !isset( $_GET['et-inc-posts'] ) && !isset( $_GET['et-inc-pages'] ) ) $postTypes = array('post');
    if ( isset( $_GET['et-inc-pages'] ) ) $postTypes = array('page');
    if ( isset( $_GET['et-inc-posts'] ) ) $postTypes[] = 'post';
    $query->set( 'post_type', $postTypes );

    if ( isset( $_GET['et-month-choice'] ) && $_GET['et-month-choice'] != 'no-choice' ) {
    $et_year = substr( $_GET['et-month-choice'], 0, 4 );
    $et_month = substr( $_GET['et-month-choice'], 4, strlen( $_GET['et-month-choice'] ) - 4 );

    $query->set( 'year', absint( $et_year ) );
    $query->set( 'monthnum', absint( $et_month ) );
    }

    if ( isset( $_GET['et-cat'] ) && $_GET['et-cat'] != 0 )
    $query->set( 'cat', absint( $_GET['et-cat'] ) );
    }
    $query->set( 'posts_per_page', (int) et_get_option( $shortname . '_searchnum_posts', '5' ) );
    } elseif ( $query->is_archive ) {
    $posts_number = (int) et_get_option( $shortname . '_archivenum_posts', '5' );

    if ( function_exists( 'is_woocommerce' ) && is_woocommerce() ) {
    $posts_number = (int) et_get_option( $shortname . '_woocommerce_archive_num_posts', '9' );
    }

    $query->set( 'posts_per_page', $posts_number );
    }
    }

    Reply To: The case of the mysterious redirect
     
    #1

Share This Page

Web Hosting