Skip to content

jbergeron03/ACF-CPT-Options-Pages

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ACF CPT Options Pages

Small addon for ACF Options. Adds ACF location for each custom post type archive

Installation

  • Upload 'acf-cpt-options-pages' to the /wp-content/plugins/ directory.
  • Activate the plugin through thePlugins menu in WordPress.
  • Create your Custom Field Group, set location rule Options Page and choose your Custom Post Type
  • Read the documentation to display your data.

Preview

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 projects is a Custom Post Type name.

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

Customization

Add in your functions.php

function cpt_projects_customize($cptmenu) {
    $cptmenu['page_title'] = 'Dev Custom title';
    $cptmenu['menu_title'] = 'Dev Custom title';
    return $cptmenu;
}

add_filter('cpt_projects_acf_page_args', 'cpt_projects_customize');

Don't forget to replace cpt_projects_ to your custom post type name :)

To-do

  • Create settings page
  • Edit menu/page title and capability
  • Turn on/off post types

License

Copyright (c) 2017, Tusko Trush

See LICENSE for more info.

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).

Contributors


Tusko Trush

Chief :D

Máté Farkas

i18n Support

Sauli Rajala

Customizations

If you have any questions on this please post an issue/question: https://github.com/Tusko/ACF-CPT-Options-Pages/issues

About

Small addon for ACF Options. Adds ACF options page per custom post type

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • PHP 100.0%