Navigation
This is archived content. Visit our new forum.

Tagged: 

  • Author
    Posts
  • #1041393
    Pbalazs89
    Participant

    Hi there,

    I’m working on a site at http://kobflex.decorolux.com

    My question is regarding the portfolio page.

    I would like to order the items in a specific way, and I found this code here on your website.

    This is for random sorting, but it would be a good start. However, I have implemented it and it does not seem to work for me. Any ideas as to why that could be the case?

    Thanks!

    function cmk_custom_order( $wp_query ) {
    /* Get the post type from the query*/
    $post_type = $wp_query->query[‘post_type’];
    /*If Post type is Portfolio*/
    if ( $post_type == ‘x-portfolio’) {
    /* Set Order to Random*/
    $wp_query->set(‘orderby’, ‘rand’);
    /* un-comment if not using random order */
    //$wp_query->set(‘order’, ‘DESC’);
    }
    }
    /* Change Order settings before displaying the Postype*/
    add_filter(‘pre_get_posts’, ‘cmk_custom_order’);

    #1041681
    Christian
    Moderator

    Hey there,

    Please see https://codex.wordpress.org/Plugin_API/Action_Reference/pre_get_posts to learn more about pre_get_posts action hook. Your code should be

    function cmk_custom_order( $wp_query ) {
    /* Get the post type from the query*/
    $post_type = $wp_query->query['post_type'];
    /*If Post type is Portfolio*/
    if ( $post_type == 'x-portfolio') {
    /* Set Order to Random*/
    $wp_query->set('orderby', 'rand');
    /* un-comment if not using random order */
    //$wp_query->set('order', 'DESC');
    }
    }
    /* Change Order settings before displaying the Postype*/
    add_action('pre_get_posts', 'cmk_custom_order');

    Hope that helps. 🙂

  • <script> jQuery(function($){ $("#no-reply-1041393 .bbp-template-notice, .bbp-no-topic .bbp-template-notice").removeClass('bbp-template-notice'); }); </script>