• Resolved almmello

    (@almmello)


    Hello,

    I can retrieve data from a specific post using the following shortcode:
    [acf field=”field_name” post_id=”1328″]

    Is it possible to query from the last entry using shortcode?
    [acf field=”anos_atividade” post_id=$last_entry]

    Thank you for your help!

    Best regards,

    Alexandre

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author fabianlindfors

    (@fabianlindfors)

    Hi, Alexandre!

    I’m not sure I’m following. Are you using Advanced Forms Pro with a shortcode? If so the shortcode should look like [advanced_form form=”FORM_KEY” post=”123″]

    Thread Starter almmello

    (@almmello)

    Hi Fabian,

    I have included a form that is adding the custom field data, but it generates new entries for each submission.

    How can I use a shortcode to query the last entry?

    I need to develop a very simple scenario, user needs to change a counter box value from a front end panel. The counter box will update its value by querying the custom field value using a short code.

    I’m able to query from a specific post using the ID, as you described, but because the form creates a new entry for every submission, the counter has no way to query the last custom field data.

    I really appreciate your help.

    Thank you!

    Alexandre

    Plugin Author fabianlindfors

    (@fabianlindfors)

    I see!

    The entries functionality is mostly for administration purposes and doesn’t work very well for user-facing functionality. This is the reason why I created the Pro version which includes post editing functionality. This allows you to create and edit existing posts with a form.

    If you don’t want to buy the Pro version you could also replicate the functionality by writing some code to pre-fill the form fields from a post and updating it on submission.

    The way you could achieve this with the Pro plugin is to set up a custom post type for storing the user input (one post for each user). Then set up a form to create/edit this post type. There is no built-in functionality to automatically find the last post for the current user but it can be achieved quite easily with a tiny bit of code which fetches the last post for the current user and uses a form to edit it. Something like this:

    
    $current_user = get_current_user_id();
    
    $args = array(
      'author' => $current_user,
      'post_type' => 'POST_TYPE'
      'posts_per_page' => 1,
    );
    
    $post_arg = 'new';
    if ( $current_user && $posts = get_posts( $args ) ) {
      $post_arg = $posts[0]->ID;
    }
    
    advanced_form( 'FORM_KEY', array( 'post' => $post_arg ) );
    

    A shortcode won’t work unfortunately as we need a bit of logic behind the choice of arguments.

    Hope this helps! ??

    Plugin Author fabianlindfors

    (@fabianlindfors)

    I’m going to close this thread for now. Re-open it if you need more help!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Query from the last entry’ is closed to new replies.