Support

Account

Forum Replies Created

  • In creating a front end edit of posts functionality, read only forms are very important.

  • Running on a MAMP server – Local.

    I have tried this code using the key for the field I want to control but, with only changing the key and then logging in with a user not an admin, when I try to edit the record it casts and error. Admin has no issues.

    My field is a number and called “Stock id”

    Field name: vehicle_stock_id
    Key: field_5f115aa7bf4ef

    Fatal error: Uncaught Error: Call to undefined function is_user_logged_id() in /private/var/tmp/8-read-only-stock-id.php:10 Stack trace: #0 /Users/john/Sites/wp-agent-kaz-20/wp-includes/class-wp-hook.php(307): edit_admin_only(Array) #1 /Users/john/Sites/wp-agent-kaz-20/wp-includes/plugin.php(233): WP_Hook->apply_filters(Array, Array) #2 /Users/john/Sites/wp-agent-kaz-20/wp-content/plugins/advanced-custom-fields-pro/includes/acf-hook-functions.php(109): apply_filters_ref_array(‘acf/prepare_fie…’, Array) #3 /Users/john/Sites/wp-agent-kaz-20/wp-includes/class-wp-hook.php(307): _acf_apply_hook_variations(Array) #4 /Users/john/Sites/wp-agent-kaz-20/wp-includes/plugin.php(189): WP_Hook->apply_filters(Array, Array) #5 /Users/john/Sites/wp-agent-kaz-20/wp-content/plugins/advanced-custom-fields-pro/includes/acf-field-functions.php(556): apply_filters(‘acf/prepare_fie…’, Array) #6 /Users/john/Sites/wp-agent-kaz-20/wp-content/plugins/advanced-custom-fields-pro/includes/acf-field-functions.php(648): acf_prepare_field(Array) #7 /U in /private/var/tmp/8-read-only-stock-id.php on line 10

    Log back in as admin user, no issues but the record remains “locked” and I have to take over.

    Wordpress version 5.9

  • How about if I want to use Linearicons?

  • Elliot,

    This may seem like a no brainer but to us coming up in skill levels, this was one of those that I struggled with for too long a time. I share this because I would hope this detail might gain more visibility for the sake of us who are learning.

    This bit here:

        $my_post = array();
        $my_post['ID'] = $post_id;

    is necessary for when you call:

        // Update the post into the database
        wp_update_post( $my_post );

    It’s not mentioned in the context of : Link:

    And although it’s more a WordPress related function than a ACF one, it’s crucial that the array handed to wp_update_post() includes the $my_post['ID'] = $post_id; bit in the array passed to it.

    Wordpress documentation the description in it’s examples:
    Link:

    Parameters #Parameters
    $postarr
    (array|object) (Optional) Post data. Arrays are expected to be escaped, objects are not. Default array.

    Default value: array()

    Doesn’t mention the necessity to pass the $post_id as: $myPostArray[‘ID’] assigned directly as that in that way. My mistake was to try and assign in this way:

    $myPostArray = array('post_id' => $post_id,
    'post_title' => $newTitle);

    This will fail with an error saying that the ID passed didn’t match.

    I spent no small amount of time figuring this out and the code example above is what made it make clear sense to me.

    It would be really great if this possible mistake was part of the documentation because it was really easy to make without the example above. It took me a good while to find this 😛

    Regards,

    -John

  • Some of us are using Oxygen Builder in case that matters for the best approach.

    In my use case I have an ID that I auto-generate and I don’t want anyone to change it – front end, backend – even an admin.

    How might I do that?

    Thanks

  • Even doing this with no other hooks is saving data:

    // Save the post
    add_action(‘acf/save_post’, ‘my_save_the_post’, 1);
    function my_save_the_post() {

    return;
    }

    Anyone? I’m stumped

  • In trying to sort this out, it seems to boil down to the fact that the post is being saved no matter what. I want to circumvent the save if certain criteria are not met. In this case, that no previous post exists with the same title in a published state.

    In my code sample, I am leaving the testing for that out because the primary issue is that I can’t seem to find a way to terminate the process before the pose gets saved. I am missing some step I think.

    In my plugin file I make a call to:

    add_action( ‘acf/pre_save_post’, ‘my_custom_post_type_function’, 1 );

    function my_custom_post_type_function() {
    // For the test, just terminate and return
    return;
    }

    My Template file to create a new post entry looks like this:

    <?php
    /**
    * Template Name: Post Entry for CPT
    *
    * @package WordPress
    * @subpackage Twenty_Twelve
    * @since Twenty Twelve 1.0
    */
    acf_form_head(); ?>
    <?php get_header(); ?>

    <div id=”primary” class=”content-area”>
    <div id=”content” class=”site-content” role=”main”>
    <?php /* The loop */ ?>
    <?php while ( have_posts() ) : the_post(); ?>
    <?php acf_form( array(
    ‘post_id’ => ‘new_post’,
    ‘new_post’ => array(
    ‘post_type’ => ‘custom-post’,
    ‘post_status’ => ‘publish’,
    ‘category’ => ‘custom-post-category’,
    ‘submit_value’ => ‘Create a new post entry’
    )

    )); ?>
    <?php endwhile; ?>
    </div>
    <!– #content –>
    </div><!– #primary –>

    <?php get_sidebar(); ?>
    <?php get_footer(); ?>

  • Ultimately what I want to do and can’t seem to circumvent, is to NOT save the post at all if a published post already exists based upon the compare criteria.

  • John, thanks for the clarification.

    For anyone following this, this idea came back from ACF support request:

    If you have named your file “page-new-post.php” then all you have to do is create a new page titled “New post” with the slug “new-post” so that the template file is used for the page.

    It was not apparent to me initially, (maybe I didn’t think this way when I read things), that this was a good way to go. I imagine if you had a very long title it might be cumbersome?

    If you have any comments or considerations on this John, please do so 🙂

  • What needs clarification in documentation (and I think understand it now but why I was thrown off course):

    There doesn’t seem to be a way for a custom page for things unless you make a custom page template file, then create a new page using the custom template file? If I use archive-{slug} for example to display a form, then I don’t have an archive listing for that post type. That doesn’t work out very well 🙂

    I have some study time in Laravel where routes are used. It seems the “Template Hierarchy” is a very controlled way of getting around using routes.

    PLEASE tell me if I am missing something and if I can do this, have a custom page for say a form, without having to create a custom template and a page for it. Display that from a menu item etc.

  • I’ll try to be more specific 🙂 I understand there are options, but let give one example of how I might want to do this. Again bear with me if this seems very basic.

    The slug for my CPT is “directory”.

    Say I wanted to have an dedicated individual directly related to the CPT. I don’t want an ‘archive’ page. I want a page that could potentially have all the other stuff, (sidebars etc.) as I presume, a template page, but the ‘content’ of the page would be the submission form. I would want to load the page from a menu item.

    As I look at the template hierarchy, I don’t want to name it archive-{slug} – right – because that is a different functionality and one that I would want to use the archive functionality for “that” purpose 🙂

    So I am confused as to where in the the template hierarchy the name I want to use fits?

    Thank you for your patience and help.

  • Ok, I wasn’t using/defining my CSS correctly.

    Live and learn I guess.

  • Dadmore,

    This plugin (acf-frontend-display) is interesting, but it should include a couple disclaimers:

    It doesn’t work with the PRO version of acf.
    The author so far has stated they are not (yet?) intending to support the PRO
    version.
    It does not use the native acf_form code. The author modified the code for this plugin.

    Again, interesting plugin idea, just feel it should include these details up front.

Viewing 16 posts - 1 through 16 (of 16 total)