J
J
JustRe1ax2021-11-06 13:25:11
Gallery
JustRe1ax, 2021-11-06 13:25:11

WordPress. Ajax load more acf for taxonomy. The field type is gallery. How to output shortcode correctly?

There is a new type of material - photo.
This photo has a taxonomy - photo category - photocat
A gallery type field has been created for the taxonomy.
At the moment I'm outputting this:

?php $photo_gallery_images = get_field( 'photo_gallery', $term_id_prefixed ); ?>
<?php if ( $photo_gallery_images ) :  ?>
  <?php foreach ( $photo_gallery_images as $photo_gallery_image ): ?>
    <a href="<?php echo esc_url( $photo_gallery_image['url'] ); ?>">
      <img src="<?php echo esc_url( $photo_gallery_image['sizes']['thumbnail'] ); ?>" alt="<?php echo esc_attr( $photo_gallery_image['alt'] ); ?>" />
    </a>
    <p><?php echo esc_html( $photo_gallery_image['caption'] ); ?></p>
  <?php endforeach; ?>
<?php endif; ?>

Accordingly, in order to display in this way, before the specified code, I prescribe all the parameters
$category = get_queried_object();
$current_cat_id = $category->term_id;
$current_cat_name = $category->name;

$taxonomy = 'photocat';
$term_list = wp_get_post_terms($post_id, $taxonomy, array('fields' => 'all'));

$taxonomy_prefix = 'photocat';
$taxonomy = get_term_by('slug', get_query_var('term'), get_query_var('taxonomy'));
$parent = get_term_by('id', $taxonomy->parent, get_query_var('taxonomy'));

$term_id_prefixed = $taxonomy_prefix .'_'. $current_cat_id;

$term_id = $term_list[0]->term_id;

Thus, everything is perfectly entered:
<?php $photo_gallery_images = get_field( 'photo_gallery', $term_id_prefixed ); ?>

                        <?php if ( $photo_gallery_images ) :  ?>
                        <div class="photo_cat_gallery">
                            <?php foreach ( $photo_gallery_images as $photo_gallery_image ): ?>
                                <a data-fancybox="photo_gallery" href="<?php echo esc_url( $photo_gallery_image['url'] ); ?>">
                                    <img src="<?php echo esc_url( $photo_gallery_image['sizes']['thumbnail'] ); ?>" alt="<?php echo esc_attr( $photo_gallery_image['alt'] ); ?>" />
                                </a>
                            <?php endforeach; ?>
                        </div>
                        <?php endif; ?>

But the customer needed to download via "show more". I'm trying to implement this through the ajax load more plugin for wordpress.
In this way:
https://connekthq.com/plugins/ajax-load-more/examp...

[ajax_load_more preloaded="true" preloaded_amount="4" posts_per_page="4" seo="true" acf="true" acf_field_type="gallery" acf_field_name="alm_gallery" seo="true" container_type="div" images_loaded="true"]


Of course, this is not displayed, because I need (as far as I understand) a taxonomy index. But I can't figure out where to put it. If who faced, or has experience, I will be very grateful to the help. I tried to add it already to the cycle, and outside, and to the conditions - it does not show ...

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question