I want to start out by saying I’m not an expert with php, but I’m slowing learning. With that said, I am using the Genesis Framework to build a website, and with Genesis is a widget to display posts. This widget allows me to exclude any previously displayed posts on the same page.
I’m using 2 Relationship fields to allow the user to select posts to be featured on the top of the homepage, and the widget should show a select number of posts excluding any posts listed on the page. My posts show up like I want them too, but the Genesis widget isn’t excluding the posts I’ve selected to be featured. Here is my code:
function magazine_featured_articles() { ?>
<div class="fa_grid ">
<div class="fa_wrapper wrap grid-4">
<?php
$main_post = get_field('main_featured_article', 'option');
if( $main_post ): ?>
<div class="fa_module fa-big-thumb">
<?php
// get the current post in the loop
global $post;
foreach( $main_post as $post): ?>
<?php setup_postdata($main_post); ?>
<div class="fa-module-thumb">
<a href="<?php the_permalink(); ?>">
<?php the_post_thumbnail( 'featured-image' ); ?>
</a>
</div>
<div class="fa-meta-info">
<a href="<?php the_permalink(); ?>">
<div class="big-grid-title"><h3><?php the_title(); ?></h3></div>
</a>
</div>
<?php endforeach; ?>
</div>
<?php wp_reset_postdata();
endif; ?>
<? $featured_post = get_field('featured_articles', 'option');
if( $featured_post ): ?>
<div class="fa-grid-scroll">
<?php foreach( $featured_post as $post): ?>
<?php setup_postdata($featured_post); ?>
<div class="fa_module fa-small-thumb">
<div class="fa-module-thumb">
<a href="<?php the_permalink(); ?>">
<?php the_post_thumbnail( 'featured-image' ); ?>
</a>
</div>
<div class="fa-meta-info">
<a href="<?php the_permalink(); ?>">
<div class="big-grid-title"><h3><?php the_title(); ?></h3></div>
</a>
</div>
</div>
<?php endforeach; ?>
</div>
<?php wp_reset_postdata();
endif; ?>
</div>
</div>
<?php }
I’m assuming that I need to run the above through the WP_Query but I’m not sure how to, or maybe there is a better way of doing this all together. I’m open to suggestions. Thank you in advance!