Emerson
Emerson

Reputation: 71

How to hide public post containing ACF plugin custom fields

I have a post where the user can modify all site texts in custom fields created with ACF plugin. Thing is, I don't want this post to show at all in any page. I tried changing it status to private, but this makes all the texts from the custom fields disappear from the website. How can I filter only this particular post out from all posts listings? Is there some way to filter it out in functions.php?

EDIT: I'm using the PRO version, in case anyone wonders about it.

Upvotes: 1

Views: 602

Answers (1)

Jurgen Oldenburg
Jurgen Oldenburg

Reputation: 179

Why would you want to store all site texts in custom fields in a post? You could better register an options page, and store all the details there. Than you don't have to hide any posts.

Register a acf options page:

<?php
// Add main options page
acf_add_options_page( array(
    'page_title'     => __( 'Options', 'textdomain' ),
    'menu_title'     => __( 'Options', 'textdomain' ),
    'menu_slug'      => 'theme-options',
    'capability'     => 'manage_options',
    'position'       => 999
) );
add_filter('init', 'options_pages');
?>

Th get fields from an options page, you need to pass the 'option' parameter to get_field() or the_field() like this:

<?php echo get_field('your-field-name', 'option'); ?>

You can read more about options fields in the ACF documentation: https://www.advancedcustomfields.com/add-ons/options-page/ https://www.advancedcustomfields.com/resources/acf_add_options_page/

Upvotes: 1

Related Questions