Support » Fixing WordPress » How to create archive page of custom fields

  • For each of my products there is a Datasheet which is linked to the product using a Custom Link field (Advanced Custom Fields).

    I would like to create a ‘Datasheets’ page, which would be an archive of the links to all these Datasheets.

    How might I go about creating this?

    On the Advanced Custom Fields forum, someone suggested using add_rewrite_rule and the single product template file. Is this the best way to go?

    Thank you!

Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    There are a number of approaches possible. A rewrite rule can be part of the solution. I don’t see how a single product template would be useful. No matter, that’s not what I would do.

    I would make a custom page template to do this, based on your theme’s page.php template. First create a new page with the desired title. No content is necessary, you are just creating a permalink to use to get to the custom template. Note the page ID and use it to name copy of the page template. If the ID is 123, name the template file page-123.php.

    On this file, remove the loop portion and replace it with code similar to the example for WP_Query. Instead of linking to a post within this new WP_Query loop, use the ACF value to link to the file.

    You must assign a query arguments array to $args for the example code to work as you want. Your arguments will include post_type product and limited to those where the ACF meta key exists. Order by something besides the default date, perhaps by product title. Details on each argument are in the linked article.

Viewing 1 replies (of 1 total)
  • The topic ‘How to create archive page of custom fields’ is closed to new replies.