D
D
DimkaMixov2020-08-15 13:03:37
WordPress
DimkaMixov, 2020-08-15 13:03:37

Post__in + ACF: all digits are not extracted or how to paginate the ACF "posts"?

Good time, dear experts! Tell me how to make pagination for the selected records of their "Posts" field in the ACF plugin

Option No. 1 (preferably)

I output the posts with the following code:

<?php $id_page_services_id = get_field( 'id_page_services_id' ); ?>
<?php if ( $id_page_services_id ) : ?>
  <?php foreach ( $id_page_services_id as $post ) : ?>
    <?php setup_postdata ( $post ); ?>
    <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
  <?php endforeach; ?>
  <?php wp_reset_postdata(); ?>
<?php endif; ?>


Everything is displayed fine, but pagination cannot be attached, as I understand it, pagination can only be attached to wp new query. I did option number 2, but this also does not work.

Option number 2

Displaying records in a normal cycle and through the ACF "Text" field I display pages by ID, everything seems to work as it should, but only the first page is displayed.

There is a regular new WP_Query

<div class="row grid img-reset">
               
               <?php
 
                  $idsss = get_field( 'id_page_services_id' ); // Кладу в переменную числа из поля (Пример - 250, 265, 669, 243)
 
                  $argss = array(  
 
                    'posts_per_page' => 12,
                    'paged' => $paged,
                    'post_type' => 'page',
 
                    'post_parent__in' => array( $idss ),   // Не работает т.к. надо (для примера)
                    'post__in'  => array( $idsss ),            // Не работает т.к. надо
                    'post__in'  => [ $idsss ],                   // Не работает т.к. надо
 
                    'post__in'  => [ 250, 265, 669, 243 ], // Так идеально работает
                    
                  )
               ?>
                            
               <?php
                  $count_items = 1;
                  $paged = get_query_var( 'paged', 1 );
                  $twoprocedd = new WP_Query( $argss );
               ?>
 
               <?php if ( $twoprocedd->have_posts() ) { while ( $twoprocedd->have_posts() ) { $twoprocedd->the_post(); ?>
 
               <a href="<?php the_permalink(); ?>" rel="bookmark" title="<?php the_title(); ?>">
                  <div class="col-lg-4 col-sm-6" style="padding-top:30px">
                     <figure class="effect-bubba" style="position:relative">
                        <?php the_post_thumbnail('thumbs-all'); ?>
                        <figcaption>
                           <div class="block-table">
                              <div class="block-table-cell">
                                 <div class="h4"><?php the_title(); ?></div>
                                 <div class="subname top-15"><?php the_excerpt(); ?></div>
                              </div>
                           </div>
                        </figcaption>
                     </figure>
                  </div>
               </a>
 
               <?php } ?>
 
               <?php wp_reset_query(); ?>
 
               <?php } else { ?>
                 <p>Нет записей для отображения.</p>
                 <style>.last-bl-none-two {display: none;}</style>
               <?php } ?>
 
</div>


Those. I understand that in the last example I extract an array from the field, but it’s not numbers, and therefore the necessary pages are not displayed.

It turns out that I write on the page in the number / ID field with the necessary pages, only the first page is displayed, and the rest of the IDs, after the comma, as I understand it, are simply ignored.

For example, I specify 250, 265, 669, 243. The page with id 250 is displayed, but the one after the first comma is gone. And if you just display a field on the page through the_field, then all the numbers are shown.

It is possible that the ACF field should not be "Text", but something else, or put this field into a variable in some other way.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Pavel Chesnokov, 2020-08-17
@DimkaMixov

If the variable contains a id_page_services_idstring, 250, 265, 669, 243then first you need to make an array out of it, for example like this:

$idsss = get_field( 'id_page_services_id' );
$idsss = explode(', ', $idsss); 
$idsss = array_filter($idsss);

And then use it as a parameter:
'post__in' => $idsss

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question