Home Forums Add-ons Repeater Field Merge options repeater fields and custom post type


Merge options repeater fields and custom post type

  • I realise this is a big ask but I can’t work out how to do this.

    I have an options page that generates publications that are just a PDF link.

    It asks for a featured image, excerpt, PDF link, and date

    I also have a custom post type called ‘publications’

    I am trying to merge these two together and then output them sorted by date (the date picker for the repeaters and the published date for posts)

    My Repeater field is setup like so:

    <?php if ( have_rows( 'publications', 'option' ) ) : ?>
    	<?php while ( have_rows( 'publications', 'option' ) ) : the_row(); ?>
    		<?php the_sub_field( 'publication_name' ); ?>
    		<?php $publication_image = get_sub_field( 'publication_image' ); ?>
    		<?php if ( $publication_image ) : ?>
    			<img src="<?php echo esc_url( $publication_image['url'] ); ?>" alt="<?php echo esc_attr( $publication_image['alt'] ); ?>" />
    		<?php endif; ?>
    		<?php the_sub_field( 'publication_description' ); ?>
    		<?php $publication_file = get_sub_field( 'publication_file' ); ?>
    		<?php if ( $publication_file ) : ?>
    			<a href="<?php echo esc_url( $publication_file['url'] ); ?>"><?php echo esc_html( $publication_file['filename'] ); ?></a>
    		<?php endif; ?>
    		<?php the_sub_field( 'file_link_description' ); ?>
    		<?php the_sub_field( 'pdf_date' ); ?>
    	<?php endwhile; ?>
    <?php else : ?>
    	<?php // No rows found ?>
    <?php endif; ?>

    My custom post type is just called ‘publications’

    ACF have said I need to:

    Create a Custom Post Type: First, you’ll want to create a custom post type specifically for the publications (e.g., “Publications”).
    Set up ACF Repeater Field: Set up an ACF repeater field group for the additional content that doesn’t fit the typical blog post format. This repeater field can include fields for an image, text, link, and date field (if you want to order by date).
    Add Content as Custom Posts or Repeater Fields: For the actual blog posts, create them using the standard WordPress post editor, and assign the “Publications” custom post type to them. For the other content that consists of just an image and a link to a PDF, use the ACF repeater field to add that information to a specific page or a custom options page.
    Custom Query to Retrieve and Display Content: Now comes the part where you combine both types of content on your publications page. In your page template (or a custom template), you’ll use a custom query to fetch both the regular blog posts and the ACF repeater field data.

    a. Retrieve Blog Posts: Use a regular loop or WP_Query to get the blog posts assigned to the “Publications” custom post type, and display them in a list or grid format.
    b. Retrieve Repeater Field Data: To fetch the data from the ACF repeater field, you can use the get_field function with the appropriate field name and iterate through the rows to display the image, text, and link.
    c. Merge and Sort: Combine the data from both sources into a single array or object and sort them based on the publishing date (you can use the date field in the repeater field).

    Display the Combined Content: Finally, loop through the sorted and merged array/object to display all the content together on the publications page.
    Remember that the actual implementation may vary depending on your specific use case and the structure of your theme. Always make sure to properly sanitize and validate any user-generated content to ensure security.

    This approach should allow you to have a flexible publications page that can include both traditional blog posts and the ACF repeater field content, presented in a unified manner sorted by date.

    But I don’t know how to do this.

    Any help would be greatly appreciated

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.