0

I set up a custom post type & taxonomy and registered it as a plugin.

Then i'm referencing it from an archive template like this:

<?php 
/*
This loop is used in the Archive [.php] template.
*/

$post_id = get_the_ID();
$artwork_id = get_post_thumbnail_id($post_id); 
$metadata = wp_get_attachment_metadata($artwork_id);
$height =  $metadata['sizes']['medium']['height'];
$width  =  $metadata['sizes']['medium']['width'];
$src = get_the_post_thumbnail_url($post_id,'medium_large');
$class = 'attachment-'.$artwork_id;
$alt = get_the_title();
?>

  <?php echo '<div class="artwork infinite-scroll-item" style="width:calc('.$width.'px * 250 / '.$height.'); flex-grow:calc('.$width.'*250/'.$height.')">'; ?>
  <?php echo '<a href="'.get_the_permalink().'" style="padding-bottom:calc('.$height.' / '.$width.' * 100%);">'; ?>
        <?php echo '<img src="'.$src.'" alt="'.$alt.'" class="'.$class.'" />'; ?>
    <strong><?php the_title(); ?></strong> <?php echo get_the_date( 'Y' );?>, <?php the_field('materials'); ?>, <?php the_field('height'); ?>x<?php the_field('height'); ?>cm, <?php the_field('availability'); ?>
    </a>
</div>

I get this error on the site: Warning: Error while sending QUERY packet. [...] /wp-includes/wp-db.php on line 2056 followed by a 503 Service Unavailable error.

Does that code look horribly inefficient? The query returns 20 posts per page and I use an infinite scroll plug-in to get further posts, approximately 50 - 80 in total.

Is there anything I could do to improve it?

3
  • Is there any more detail with the error, e.g. a response from the database or a connection failure? You can use the Query Monitor plugin to see how many queries you're actually generating.
    – Rup
    Commented Feb 16, 2021 at 14:29
  • But your example looks sensible: the ACF the_field() calls are just postmeta and I think that's all loaded in one go and not individually per field request.
    – Rup
    Commented Feb 16, 2021 at 14:30
  • Thanks for looking, I spoke to the host (Hostinger) who said I was using too many resources. I'm in the process of developing the site to I am repeatedly loading that page but I didn't think it was an excessive amount. I will try Query Monitor and see what it says!
    – Andy
    Commented Feb 16, 2021 at 14:46

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.