Support

Account

Home Forums ACF PRO ACF with Social Article

Solving

ACF with Social Article

  • @markbloomfield

    Hi, I’ve just purchased ACF Pro.Order#109768

    Referring to the Pre-purchase question here https://support.advancedcustomfields.com/forums/topic/can-acf-do-this-with-social-article/, what do I have to do next? I already created a field group, my form.

  • Hi @topy

    Ok, so the steps would be as follows:

    1) create the form group with all the fields you want to be on your post
    2) create a page in wordpress where this form will ‘live’
    3) open your functions.php and add these 2 bits of code:

    
      /*----------  User Info  ----------*/
      // this creates a global 'USERID' which you can use to return the ID of the current user anywhere in your site
      if (is_user_logged_in()) {
        $current_user = wp_get_current_user();
        define('USERID', $current_user->ID);
      }
    
      /*----------  Check if I am an admin  ----------*/
      function is_administrator() {
        $current_user = wp_get_current_user();
        $roles = $current_user->roles;
    
        return (in_array('administrator', $roles)) ? true : false;
      }
    

    4) create a new page template to apply to this page (assuming you know how to do this?)
    5) in that template, put this at the very top of your file:

    
    <?php
    
      /**
       *      Is something being edited?
       *      Is the user trying to do this, the author of the post being edited?
       *      If not, redirect back to home
       */
      if (isset($_GET['edit'])) {
        // get the post being edited
        $thispost = get_post($_GET['edit']);
        if (USERID == $thispost->post_author || is_administrator()) {
          $new_post = $_GET['edit'];
        } else {
          header('Location: '.get_bloginfo('home'));
          exit;
        }
      } else {
        $new_post = 'new_post';
      }
    
      /* Template Name: My Post Create Page */
    
      acf_form_head();
      get_header();
    ?>
    

    You will use this page for both post creation, and post editing. To edit the post, just add ?edit=23 to the URL and that will let you edit post 23. Note that the above function will only let the author of post 23, or the administrator edit this post. Anyone else will be redirected to the home page

    6) Where you want the edit form to appear, put this code:

    
    <?php
      $formoptions = array(
        'post_title'      => true,
        'post_content'    => false,
        'post_id'         => $new_post,
        'new_post'        => array(
          'post_type'       => 'insights', // change this to the post type you need
          'post_status'     => 'publish' // do you want the post to be published immediately? otherwise change this to 'draft'
        ),
        'field_groups'    => array(999999), // change this number to the ID of your field group
        'submit_value'    => 'Publish',
        'return'          => get_permalink(142), // change this ID to the page you want to send the user back to when they've submitted the form - perhaps a thank you page
        'uploader'        => 'wp'
      );
      acf_form($formoptions);
    ?>
    

    —————–

    That should do the trick. Give it a go and let me know if you get stuck.

    Good luck!

  • @markbloomfield

    Thank you very much for your instruction. However, I have been through the step 1 to 5 but nothing happens. This is what I have done:

    1. I created a form group.
    2. I created a page to display this form.
    3. I put the 2 bits of code into the function.php in my child theme.
    4. I created a new page template. I do this by adding the given code from your instruction#5 into Notepad. Then I add this template page (.php) into my theme directory. After that I go back to the page I have created earlier (instruction#2). Under Page Attributes, I select the template page I’ve just created. Finally, update and view the result. I see nothing on that page. Also clear cache still nothing comes.

    Note: In the Location rule in ACF, I have also tried both rules below but it does’t work:
    1. Show this field group if PAGE equal to “the page I create for the form”
    2. Show this field group if Page Template equal to “the template page I create for the form.”

  • @topy are you able to give me a URL and logins to this site perhaps so I can help?

  • @markbloomfield

    I am creating a website locally using WampServer. How can I do to let you access to my file so that you can check?

  • @topy the site would need to be online somewhere for me to check. Do you have a staging/test server you can upload the site to? That would make it a lot easier to check 🙂

    Worst case scenario, is you can send me a backup of your entire site, and a backup of the .sql file and I can set it up on my localhost and check what’s happening…

    Whichever is easier for you.

  • @markbloomfield

    I am new to WordPress. This is my first time to create a website with WP. And I haven’t decided on any web hosting yet. I don’t know about staging/test server you are referring to, and also to back up the .sql, I don’t know how to do either.

    To make sure there’s no any conflict, I even have created a new database and installed a new WordPress file, new theme file is also replaced. Everything is new. Then I install only ACF Pro and repeat the instructions, the result is still the same. I think there must be something wrong with the tutorial you give me?

  • @topy the tutorial I gave you, is what I did on a site of my own in the last 2 weeks, so it definitely works.

    But i’d like to help check your code + setup on my end. If you don’t have a server to upload this to yet, then you can:

    1) zip up the whole WP folder for the site and upload it somewhere and give me the link here

    2) if you’re using WAMP, you should be able to browse to http://localhost/phpmyadmin to gain access to your databases so you can export them. Export the SQL file for your site and zip this up too and reply here with a link to both files. If you can’t get this right, then you can also find + install a plugin that will create a backup of your database and let you download it.

    Will wait for your reply here with those files 🙂

  • Thanks @topy

    You had missed out step 6 from my tutorial completely – IE the code to actually show the form, was not placed into your Form.php page template.

    I did this, and the form showed immediately 🙂

    Screenshot of how the code should look: http://d.pr/i/QF9CP9
    Screenshot of your site with the form: http://d.pr/i/ZBtAym

    So all you need to do is open your Form.php and put this code wherever you want the form to appear:

    
    <?php
    	$formoptions = array(
    		'post_title'      => true,
    		'post_content'    => true,
    		'post_id'         => $new_post,
    		'new_post'        => array(
    			'post_type'       => 'post', // change this to the post type you need
    			'post_status'     => 'publish' // do you want the post to be published immediately? otherwise change this to 'draft'
    		),
    		'field_groups'    => array(9), // change this number to the ID of your field group
    		'submit_value'    => 'Publish',
    		'return'          => get_permalink(24), // change this ID to the page you want to send the user back to when they've submitted the form - perhaps a thank you page
    		'uploader'        => 'wp'
    	);
    	acf_form($formoptions);
    ?>
    

    Hope this helps 🙂

  • @markbloomfield

    Absolutely, my mistake to skip the #6 as I think it has to be done the other step, my confusion,sorry.But Why we have two forms in one page. The first form has title field and content field from this one (‘post_title’=> true,’post_content’=> true,). And the second form is the form from the group field. When I go to this form page to create a new post, I have to fill up the information into both forms. How can I separate them?

    I added a post id at the end of the url. This brings an edit screen to the first form. Hmmm, as I told you that I use Social Article. Posts that users create are listed in the tab in user profile. There there’s an edit button to every post. When users click on that edit button, how to bring users to that edit screen? How can I edit the path? Please see the picture. https://www.dropbox.com/s/w9dl0z8yl1qt9cg/123.jpg?dl=0

    And next to Publish button, can I have Save to Draft button, totally two buttons.

    Thanks.

  • Finally, I have been deluded to buy the plugin.

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

The topic ‘ACF with Social Article’ is closed to new replies.