• I am using the “notes” modification that adds a note column to the database. Some of my products include notes, while others don’t. Is there any way that I can display products with notes before products without notes in the search results? I can’t figure out how to adjust the sorting in the search results, or if I can even change the sorting to display products with notes first. Is this possible?

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

    (@pektsekye)

    Hello,

    Can you send the file:
    wp-content/plugins/ymm-search/Controller/Product.php

    to me by email [email protected]

    ?

    Stanislav

    Plugin Author Pektsekye

    (@pektsekye)

    Hello,

    For someone else who have applied the “Notes” modification and need to change the order of the listed products on the search results page:

    After the line:

    
        add_filter('get_search_query', array($this, 'shop_order_search_label' ));
    

    add this code:

    
        if (isset($_GET['ymm_search'])){
          add_filter('posts_join', array($this, 'join_ymm_table'));
          add_filter('posts_orderby', array($this, 'order_products_by_ymm'));
        } 
    

    Then add two new functions:

    
    function join_ymm_table ($join) {
          global $wpdb;
          $posts_stats_table = $wpdb->prefix . "posts_stats";
          $posts_stats_view_join = "JOIN {$wpdb->prefix}ymm AS ymm ON $wpdb->posts.ID = ymm.product_id";
          $join .= $posts_stats_view_join;
          return $join;
      }
    
      function order_products_by_ymm ($orderby) {
        global $wpdb;
        $posts_stats_table = $wpdb->prefix . "posts_stats";
        $orderby = "if(ymm.note = '',0,1)," . $orderby;
        return $orderby;
      }
    

    in the file:
    wp-content/plugins/ymm-search/Controller/Product.php

    Stanislav

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Can I change sorting to display products with notes first?’ is closed to new replies.