Advanced Custom Fields : CPT Options Pages

Description

Usage

The default functions of ACF plugin (get_field, the_field, etc.) can be used to load values from a CPT Options Pages, but second parameter is required to target the CPT options.

This is similar to passing through a $post_id parameter to target a specific post object.

The $post_id parameter needed is a string containing the cpt_ and CPT name in the following format: "cpt_{CPT_NAME}"

Examples

In examples Custom Post Type name is projects.

So, let’s go!

Display a field

<p><?php the_field('field_name', 'cpt_projects'); ?></p>

Retrieve a field

<?php
    $field = get_field('field_name', 'cpt_projects');
    // do something with $field
?>

Display a sub field

    <?php if( have_rows('repeater_name', 'cpt_projects') ): ?>
        <ul>
            <?php while( have_rows('repeater_name', 'cpt_projects') ): the_row(); ?>
                <li><?php the_sub_field('the_title'); ?></li>
            <?php endwhile; ?>
        </ul>
    <?php endif; ?>

Display with shortcode

[acf field="field_name" post_id="cpt_projects"]

Please read documentation about shortcodes with ACF

License

Copyright (c) 2016, Tusko Trush

Requirements

You must buy ACF PRO or ACF Options Page Addon.

Translation

qTanslate-X

If you are using Qtranslate-X, you must install ACF Qtranslate.

WPML/Polylang

If you are using WPML or Polylang, you must add constant ICL_LANGUAGE_CODE to post_id,
for example: get_field('archive_title', 'cpt_projects_' . ICL_LANGUAGE_CODE).

Screenshots

  • assets/screenshot-1.png

Installation

  1. Upload ‘acf-cpt-options-pages’ to the ‘/wp-content/plugins/’ directory.
  2. Activate the plugin through the ‘Plugins’ menu in WordPress.
  3. Create your Custom Field Group, set location rule ‘Options Page’ and choose your ‘Custom Post Type’
  4. Read the documentation to display your data.

FAQ

If you have any questions on this please post an issue/question at Github Issues

Reviews

Excellent Plugin

Smart, intuitive and works exactly as advertised. Just what I needed for archive pages custom headings but I’m certain I will find other ways of using this excellent tool.

Read all 5 reviews

Contributors & Developers

“Advanced Custom Fields : CPT Options Pages” is open source software. The following people have contributed to this plugin.

Contributors

Changelog

1.1.0

  • WPML and Polylang compatibility added.

1.0.2

  • Update documentation.
  • Change labels and slugs.

1.0.1

  • Plugin created.