Join the Soledad Facebook Users Group here
for Share, assistance, discussion, and Updates related to Soledad WordPress Theme.

If you can't create a new ticket - you can send us an email via our contact form and we will get back to you.

Okay
  Public Ticket #1829553
Tweaking Functionality
Closed

Comments

  • scrawjiji02 started the conversation

    I was wondering if you guys could help me out with a code snippet showing how I could sort posts by PostViewCount rather than Date/Random/ID. I know it's possible and I'm sure you guys know how to achieve this. I just can't seem to find the code that creates this functionality or else I'd try editing it myself. 

    I understand some of the functionality lies in functions.php but I can't seem to find where the initial penci_custom_posts_oderby() function is located.

    Could you guys please just do up a quick code edit and send it to me? Literally just show me where to put my ViewCount variable to have it sort based on that variable. 

    I'm really enjoying the theme, amazing work! 

    Thanks so much,

    Shaugn

  •  2,699
    PenciDesign replied

    Hi,

    Please open functions.php file and find function penci_custom_posts_oderby:

    if ( ! function_exists( 'penci_custom_posts_oderby' ) ) {
        function penci_custom_posts_oderby( $query ) {
            if ( ( $query->is_home() && $query->is_main_query() ) || ( $query->is_archive() && $query->is_main_query() ) ) {
                $orderby = get_theme_mod( 'penci_general_post_orderby' );
                if( !$orderby ): $orderby = 'date'; endif;
                $order = get_theme_mod( 'penci_general_post_order' );
                if( !$order ): $order = 'DESC'; endif;
                
                if( ! function_exists( 'is_woocommerce' ) || ( function_exists( 'is_woocommerce' ) && ! is_woocommerce() ) ) {
                    $query->set( 'orderby', $orderby );
                    $query->set( 'order', $order );
                }
            }
        }
        add_action('pre_get_posts','penci_custom_posts_oderby');
    }

    Let's replace it to:

    if ( ! function_exists( 'penci_custom_posts_oderby' ) ) {
        function penci_custom_posts_oderby( $query ) {
            if ( ( $query->is_home() && $query->is_main_query() ) || ( $query->is_archive() && $query->is_main_query() ) ) {
                $orderby = get_theme_mod( 'penci_general_post_orderby' );
                if( !$orderby ): $orderby = 'date'; endif;
                $order = get_theme_mod( 'penci_general_post_order' );
                if( !$order ): $order = 'DESC'; endif;
                
                if( ! function_exists( 'is_woocommerce' ) || ( function_exists( 'is_woocommerce' ) && ! is_woocommerce() ) ) {
                    $query->set( 'meta_key', 'penci_post_views_count' );
                    $query->set( 'orderby', 'meta_value_num' );
                    $query->set( 'order', 'DESC' );
                }
            }
        }
        add_action('pre_get_posts','penci_custom_posts_oderby');
    }
    

    Best Regards,

    PenciDesign

  • scrawjiji02 replied

    Thanks a ton!!!! How hard would it be to setup functionality for setting up a link/dropdown options on the category/index template pages where a user can click and it will sort all post teasers on the page by ViewCount, Date, Random, etc either via page refresh or ajax, I don't care really. 

    Have you guys done this sort of functionality for anyone? If so I would greatly appreciate if you'd point me in the right direction. Your theme is amazing albeit a bit advanced for me at the moment. I just need this last functionality to finish the site. Any information would be amazing!

    Kind regards,

    Shaugn

  •  2,699
    PenciDesign replied

    Hi,

    Thank you for loving our theme.

    Unfortunately, this theme doesn't support this feature at this time..

    That's too much work to do and we don't provide support for requirements like that.

    Best Regards,

    PenciDesign