• Hi have to display the product by his category name and his event end date with end date my query is working properly it shows the all upcoming date product.

    but my client wants to display a specific category product like category name “agriculture” so how can edit the bellow query to retrieve product according to upcoming date and the category is=”agriculture”.

    table structure of category terms:-
    click here

    $sql = 'select p.ID, p.post_title, m2.meta_value  from ' . $wpdb->posts . ' p ' .
                    ' left join ' . $wpdb->postmeta . ' m1 on m1.post_id = ID ' .
                    ' left join ' . $wpdb->postmeta . ' m2 on m2.post_id = ID ' .
                    ' where post_status = "publish" AND ( post_type = "product" OR post_type = "ignitewoo_event" ) ' .
                    ' AND ( m1.meta_key = "_ignitewoo_event" AND m1.meta_value = "yes" ) ' .
                    ' AND ( m2.meta_key = "_ignitewoo_event_end" AND m2.meta_value >= "' . date( 'Y-m-d H:i:s', current_time( 'timestamp', false ) ) . '" ) ' .
                    ' AND ( m2.meta_key = "_ignitewoo_event_end" AND m2.meta_value != "" ) ' .
                    ' ORDER BY CAST( m2.meta_value as DATE ) ASC LIMIT ' . $number ;
    
                $posts = $wpdb->get_results( $sql );
  • The topic ‘Display product by category name’ is closed to new replies.