Support

Account

Home Forums ACF PRO Insert unique ID before first instance of field Reply To: Insert unique ID before first instance of field

  • I’m sorry for the confusion John. Okay, so I have 800 or so custom_post_types (records) which each have a letter they are being sorted by (either the first name of the musical artist or the band name). These values are chosen inside the custom_post_type via an ACF. WordPress then uses the standard while loop to list out all of the records (which are already in the correct order).
    So what I am looking to do is have the code determine where the first custom_post_type with an ACF ($sort) value of “A” is being looped in, and inject a custom div with the text “A” before that. Then before first custom_post_type ACF value or “B” begins, inject a custom div with “B” in… and so on and so fourth all the way until “Z”.
    So I am not sure if the best methodology would be to do a php count of all the custom_post_types with the ACF ($sort) value of “A”, “B”, “C”, etc before the while loop and then just have some custom php conditional statement tied into the while loop so that the code knows that after 200 or so entries it needs to insert some html code identifying that the user is now viewing “B” custom_post_types so, then at 340 “C”, etc.
    The end code I am hoping the html spits out is…

    <div id="ajax" class="records row">
       <div id="artist-a">A</div>
       <div class="record col-xs-6 col-sm-4 col-md-3 col-lg-2 col-xl-2">A01</div>
       <div class="record col-xs-6 col-sm-4 col-md-3 col-lg-2 col-xl-2">A02</div>
       <div class="record col-xs-6 col-sm-4 col-md-3 col-lg-2 col-xl-2">A03</div>
       <div class="record col-xs-6 col-sm-4 col-md-3 col-lg-2 col-xl-2">A04</div>
       <div id="artist-b">B</div>
       <div class="record col-xs-6 col-sm-4 col-md-3 col-lg-2 col-xl-2">B01</div>
       <div class="record col-xs-6 col-sm-4 col-md-3 col-lg-2 col-xl-2">B02</div>
       <div class="record col-xs-6 col-sm-4 col-md-3 col-lg-2 col-xl-2">B03</div>
       <div id="artist-c">C</div>
       <div class="record col-xs-6 col-sm-4 col-md-3 col-lg-2 col-xl-2">C01</div>
       <div class="record col-xs-6 col-sm-4 col-md-3 col-lg-2 col-xl-2">C02</div>
       <div class="record col-xs-6 col-sm-4 col-md-3 col-lg-2 col-xl-2">C03</div>
       <div class="record col-xs-6 col-sm-4 col-md-3 col-lg-2 col-xl-2">C04</div>

    Of course these numbers are dynamic and dependent on however many entries (custom_post_types) exist in the back-end of the system.