Forums Forums Search & Filter Pro Create “top 10” lists of CPTs grouped by ACF field value

  • This topic has 13 replies, 3 voices, and was last updated 4 years ago by Ross.
Viewing 10 posts - 1 through 10 (of 14 total)
  • Anonymous
    #264697

    Hello,
    I have a website with job openings. These jobs are a CPT (WP Job Manager), to which I regularly import jobs. The jobs have a number of ACF fields (such as company and location).

    What I am trying to achieve:
    – Create a widget that will show me the top 10 companies with the most job openings (sorted by highest number first).
    – Create a widget that will show me the top 10 locations with the most job openings.

    I am testing with S&F, but all I get is a list of companies with (0) behind it.

    Can you tell me if what I’m trying to do is possible with S&F, and what I’m doing wrong?

    Thank you very much!
    Kind regards,
    Boris Hoekmeijer

    Trevor
    #264703
    This reply has been marked as private.
    Anonymous
    #264759
    This reply has been marked as private.
    Trevor
    #264872
    This reply has been marked as private.
    Anonymous
    #264903

    Hi Trevor,
    that helps, thanks. List is a lot shorter now :-).

    However, there are still some things not the way I would want them:
    – I want to show only a top 10 of companies (those with the most job openings).
    – Each item is now displayed with a checkbox. It should be a list with 1 through 10.

    Is this possible?

    Trevor
    #264927
    This reply has been marked as private.
    Anonymous
    #264938
    This reply has been marked as private.
    Trevor
    #265108

    ah yes, because this is the form, posts per page is not applied. You need to change the field display using this filter:

    https://searchandfilter.com/documentation/action-filter-reference/#filter-input-object

    And cut the array to just 10 ‘terms/labels’.

    Anonymous
    #265214

    Hi Trevor,
    thanks for the link, but I’m not sure what I should do now.
    I understand I have to enter the field name it concerns:

    
    function filter_function_name($input_object, $sfid)
    {
      if($input_object['name']=='_company_name')
      {
        //udpate this field before rendering
      }
      
      return $input_object;
    }
    add_filter('sf_input_object_pre', 'filter_function_name', 10, 2);
    

    But beyond that, I don’t know how to trim it down to 10 and how to sort them by number. I went through the code on the github page that is referred to, but that doesn’t bring me further. Can you help me get this right?

    Trevor
    #265217

    I can’t see a code snippet that shows how to sort by count (I am not sure IF it can be done), so I have referred this to the plugin developer, Ross, for his input.

Viewing 10 posts - 1 through 10 (of 14 total)