Support

Account

Forum Replies Created

  • Update II: In response to the issue of my thumbnails not displaying; I have figured this out if anyone else with similar issues stumbles into this…

    Basically, for me, I eliminated the then unnecessary pre_get_posts filter and then replaced;

    <?php $image = wp_get_attachment_image_src(get_field('event_thumbnail'), 'full'); ?>
    <img src="<?php echo get_field('event_thumbnail'); ?>" alt="<?php echo get_the_title(get_field('event_thumbnail')) ?>" />

    with:

    <?php $image = get_field('event_thumbnail'); ?>
    <img src="<?php echo $image; ?>" alt="<?php echo get_the_title(get_field('event_thumbnail')) ?>" />

    For some reason (probably some conflict again), wp_get_attachment_image_src returns as false. But get_field('event_thumbnail') returns the image anyway, so all that was needed was to remove this wp_get_attachment_image_src function!

    Hope this helps someone!

  • Update: my original problem has been solved with John’s help, thanks very much! Because of this, this problem has obviously been solved. I will continue on with this thumbnail problem myself and possibly another support topic. Thank you!

  • Hi John,

    Thank you, I have tried that and this does help a little – now the file is loaded in and the repeater fields appear correctly. Thank you!

    To be clear what I have tried is replacing the $url = $_SERVER... code block with the one you provided, and also deleting the pre_get_posts code block (this step makes no major difference).

    However, the issue of the thumbnails loading in is still present, unfortunately.

    The relevant code for this is;

    <?php echo 'text6'; ?>
                    <div class="img-thumbnail">
    				    <a href="<?php the_permalink() ?>">
    					    <div class="price-per-person">
    						    <span>FROM <br/><strong><?php echo get_field("price_from") ? "$" . get_field("price_from") : "$" . get_field("price_per_person") ?></strong> <br/>pp</span>
    					    </div>
                            <?php $image = wp_get_attachment_image_src(get_field('event_thumbnail'), 'full'); ?>
                            <img src="<?php echo $image[0]; ?>" alt="<?php echo get_the_title(get_field('event_thumbnail')) ?>" />
          					        <?php
        				            ?>
    				    </a>
    				    <?php echo 'text7'; ?>
                    </div>
                  </div>

    All the text (the titles & price per person etc) loads in fine, as does all the textX tests, however there is still no image or thumbnail.

    Many thanks

  • I’m afraid John I don’t understand what this means, I don’t understand anything about queries / $query – this template is from a third party.

    All I do know is that adding

    if (is_admin() || !$query->is_main_query()) {
         return;
     }

    to the add_action... code caused this…

    Would you be able to explain what you’ve said in a few more steps please?

  • 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

  • Hi John, ok thanks very much for that!

    Apologies for the much later reply, but I have found some of the code that you mentioned. In the file used for the thumbnails there is the following code;

      add_action( 'pre_get_posts', 'add_my_post_types_to_query' );
      function add_my_post_types_to_query( $query ) {
        $query->set( 'post_type', array( 'post', 'event' ) );
        return $query;
      }

    So now this is finally all making sense – this is the main problem here (whenever this file is being used and this code is executed, the repeater fields failed to load as described). And whenever this file is used, the thumbnails work and the repeat fields don’t. Thanks very much for helping me find this!

    Now can I ask if you have any idea on how to fix this? As I say I didn’t create this theme so I’m not sure on how it works, so your help would be very much appreciated!

    Thanks,
    Aidan

  • Hi John,

    Thanks very much! Yes, apologies for the confusion – none of the website, the custom theme, or this code was done by myself, so I am still learning as I go along.
    But yes I believe it is repeater fields I am talking about and not galleries.

    Yes I have tried disabling all other plugins, and the error still persists so this must be the custom theme causing this.
    These repeater fields are part of the custom theme so I haven’t tried changing theme. But I’m sure it is the custom theme causing this, namely the code to get thumbnails doing this (as I mentioned in the post) as when that code isn’t used the repeater fields work fine. Again, see the post for the actual code for getting the thumbnails.

    Do you have any idea of beginning to figure this out (now that we know what code is causing it)?

    Thanks very much!

  • Hi John!

    Thanks for this, I have just tried that myself but it had no effect, unfortunately. But I have figured out much more about this and have created a new post here;

    https://support.advancedcustomfields.com/forums/topic/get_field-occassionally-returning-string-with-repeater-field/

    Apologies for the inconvenience.

Viewing 8 posts - 1 through 8 (of 8 total)