
I want to create a “related posts” option for a CPT that’s manually related. Page links is perfect for that.
But I also want to display related posts on the front end in a drop down.
I’m groping around in the dark with this, but rather enjoying myself. And thought something like this might work:
function wpwoof_resource_sidebar() {
?>
<section class="widget resource-toc">
<div class="widget-wrap">
<h3><?php _e( 'Document Details', 'wpwoof-plugin' ); ?></h3>
<div class="document-meta">
<ul>
<li><strong>Title:</strong> <?php the_field('document_name'); ?></li>
<li><strong>Download:</strong> <a target="blank_" href="[i4w_s3link protocol='http' object='<?php the_field('s3_file_path'); ?>']"> <span class="dashicons dashicons-download" style="font-size: 72px; display: block; width: fit-content; height: auto;"></span></a></li>
<li><strong>Version:</strong> <?php the_field('version_control_number'); ?></li>
<li><strong>Last Updated:</strong> <?php the_time('F jS, Y'); ?></li>
</ul>
<div class="dropdown">
<button onclick="myFunction()" class="dropbtn">Dropdown</button>
<div id="myDropdown" class="dropdown-content">
// vars
$urls = get_field('urls');
// check
if( $urls ): ?>
<?php foreach( $urls as $url ): ?>
<a href="<?php echo $url ?>"><?php echo $url; ?></a>
<?php endforeach; ?>
<?php endif; ?>
</div>
</div>
</div>
</div>
</section>
<?php
}
Now, it’s not working (no surprises), but am I on the right lines, or completely miles away?
One option would be to create a front-end form and just include that one field in the form:
The documentation is here: Front end form