Support

Account

Home Forums Add-ons Repeater Field get_field occassionally returning string with repeater field Reply To: get_field occassionally returning string with repeater field

  • Hi John,

    Thanks for that & apologies for the delayed reply. I have tried this solution – it does allow the repeater fields to populate ok, but at the expense of the thumbnails not appearing and the relevant code not running.

    I have found this is to do with $query.

    Below is the relevant code, echo tests were done throughout

    add_action( 'pre_get_posts', 'add_my_post_types_to_query' );
      function add_my_post_types_to_query( $query ) {
        // test to make sure this is the main query
        // and not the admin
        if (is_admin() || !$query->is_main_query()) {
          return;
        }
        $query->set( 'post_type', array( 'post', 'event' ) );
        return $query;
      }
    
      the_post();
      $url = $_SERVER['REQUEST_URI'];
      $url = explode("/", $url);
      $field = $url[count($url)-3];
      $value = $url[count($url)-2];
      $query = new WP_Query( array(
        'numberposts' => -1,
        'category_name' => $value
      ));
    ?>
    
    <?php echo 'text1'; ?>
    <div class="row">
      <?php echo 'text2'; ?>
      <div class="col-md-9">
        <?php echo 'text3'; ?>
        <?php get_template_part('templates/page', 'header'); ?>
        <?php the_content(); ?>
        <?php echo 'text4'; ?>
        <?php while ($query->have_posts()) : $query->the_post(); ?>
          <?php echo 'text5'; ?>
          <article <?php body_class("event") ?>>
            <div class="well">
              <div class="container">
                <div class="row">
                  <div class="col-md-4">
                    <?php echo 'text6'; ?>
                    <div class="img-thumbnail">........

    And on the site, the echo call for ‘text5’ is not met, only up to ‘text4’. So I guess this is because <?php while ($query->have_posts()) : is never met because if (is_admin() || !$query->is_main_query()) is true?

    Do you know how to proceed with this? As I say this is way out of my comfort zone, so your help is really appreciated!

    Many thanks,
    Aidan