Support

Account

Home Forums Front-end Issues Custom fields blocked

Solved

Custom fields blocked

  • Hello community,

    I have the problem that the use of my ACF is blocked. I use a code snippet on the homepage that I found on the Internet and that fulfills its task so far. This enables the last 3 posts of a respective category to be displayed. If I now use an ACF afterwards, it is no longer displayed. Delete the snipped everything works well. I hope you can help me.

    Thank you.

    Code Snipped:

    <div class="row py-4">
    	<div class="col-md-12 mb-2">
    		<h3>Kampagne 2020</h3>
    	</div>
    	<?php
    		$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    		$args = array(
    			'category_name' => 'kampagne-2020',
    			'orderby' => 'date',
    			'post_type' => 'post',
    			'posts_per_page' => 3,
    			'paged' => $paged,
    		);
    		$wp_query=new WP_Query($args);
    		if ( $wp_query->have_posts() ) :
    			while ( $wp_query->have_posts() ) : $wp_query->the_post();
    				$background = get_the_post_thumbnail_url(get_the_ID(), 'full');
    
    				$category = get_the_category();
    				$category_class = $category[0]->slug;            
    	?>
    	<div class="col-xl-4 col-lg-6 col-md-6 d-flex mb-2">
    		<div class="front-kampagne-2020">
    			<?php if ( has_post_thumbnail() ) : ?>
    				<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
    					<?php the_post_thumbnail('full', array('class' => 'img-fluid mb-2')); ?>
    				</a>
    			<?php endif; ?>
    			<?php the_title( sprintf( '<h3><a href="%s" rel="bookmark">', esc_url( get_permalink() ) ),	'</a></h3>' ); ?>
    			<p class="excerpt"><?php echo excerpt(25); ?></p>
    			<a href="<?php the_permalink(); ?>" class="read_more"><button type="button" class="understrap-read-more-link">Weiterlesen...</button></a>
    		</div>
    	</div>
    	<?php endwhile; ?>
    		<?php wp_reset_postdata(); else: ?>
    			<h5>Es gibt keine Ergebnisse, die Ihren Suchkriterien entsprechen</h5>
    		<?php endif; ?>
    </div><!-- /Kampagne 2020 -->
  • Ok, I found I simple solution for the problem:

    <?php 
    $args = array(
     'category_name' => 'kampagne-2020',
     'post_type' => 'post',
     'posts_per_page' => 3,
     'orderby' => 'rand'
    );						 
    $custom_query = new WP_Query($args); 
    if ($custom_query->have_posts()) : while($custom_query->have_posts()) : $custom_query->the_post(); ?> 
Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Custom fields blocked’ is closed to new replies.