List only publishers items

Home Forums Product Support Forums Ajax Search Pro for WordPress Support List only publishers items

This topic contains 3 replies, has 2 voices, and was last updated by msamavi64 msamavi64 2 years, 1 month ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #36941
    msamavi64
    msamavi64
    Participant

    Hello,

    I am using the Index Table engine that indexes all types of posts with any status (publish, draft, private, …).
    I have two search instances: [wd_asp id=1] and [wd_asp id=2]
    I want to use the first instance on the front page for customers that need to list only products with the status “Published”.
    I want to use the second search instance on the backend to admin and shot manager use that needs to list any post type with any status.

    Can you provide any snippet for the first search instance so as to limit its listing to published posts, please?

    Thanks and regards,
    Majid

    #36953
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi Majid,

    Based on your description, I recommend trying this custom code:

    add_filter( 'asp_results', 'asp_hide_by_status', 10, 2 );
    function asp_hide_by_status( $results, $search_id ) {
      foreach ($results as $k=>$r) {
        if ( isset($r->post_type) ) {
    		if ( $search_id == 1 && get_post_status($r->id) != 'publish' ) {
    			unset($results[$k]);
    		}
        } 
      } 
      return $results;
    }
    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


    #36955
    msamavi64
    msamavi64
    Participant

    Hi,

    Thank you.
    Can you limit the results for the first instance [wd_asp id=1] to WooCommerce Products and LearnDash Courses, please?

    Kind regards,
    Majid

    #36963
    msamavi64
    msamavi64
    Participant

    Hi,

    In my initial tests, all seems working perfectly.
    Doing more tests

    Regards,
    Majid

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.