Support

Account

Home Forums General Issues post_id is not defined

Solving

post_id is not defined

  • Hello,

    Thanks in advance for any help with this, and your patience…I’m not too familiar with WordPress (WP) so responses may need a little more instruction if I’ll be checking anything. Hopefully I have this under the right forum.

    The site I’ve inherited uses a custom plugin, which appears to integrate ACF (“repeater”…I think). Note that I don’t see AFC listed in the plugins section of WP, only references in PHP in the custom plugin that runs part of the site.

    With a recent WP upgrade, a feature stopped working. The feature has two side-by-side boxes when adding/editing an article. The left box contains a list of existing WP articles, and the right box is by default blank. When the user clicks an article on the left it moves it to the right box, meaning it’s now related to that article. The opposite can be done in the right box to remove the relationship.

    The issue is that when a user clicks on either side, nothing happens. , but the following Chrome console error. Any ideas? What can I begin checking?

    VM2241:6 Uncaught ReferenceError: post_id is not defined
    at HTMLUListElement.eval (eval at m.template (underscore.min.js?ver=1.8.3:5), <anonymous>:6:9)
    at HTMLUListElement.c (underscore.min.js?ver=1.8.3:5)
    at HTMLUListElement.<anonymous> (jquery.js?ver=1.12.4:3)
    at Function.each (jquery.js?ver=1.12.4:2)
    at jQuery.fn.init.each (jquery.js?ver=1.12.4:2)
    at Ha (jquery.js?ver=1.12.4:3)
    at jQuery.fn.init.append (jquery.js?ver=1.12.4:3)
    at Object.add (input.js?ver=4.4.3:3112)
    at HTMLAnchorElement.<anonymous> (input.js?ver=4.4.3:3200)
    at HTMLDocument.dispatch (jquery.js?ver=1.12.4:3)

  • What you are describing is a relationship field https://www.advancedcustomfields.com/resources/relationship/ and not a repeater, unless the relationship is a sub field of a repeater.

    Not sure if any of this will help you or not.

    Your site is using ACF version 4.4.3 This is a guess based on this part of the error message input.js?ver=4.4.3 The free version of ACF is now at version 4.4.11

    Since you cannot see ACF listed in the plugins you are correct that it is either installed as part of another plugin or it is installed as part of your theme. There’s not an easy way to figure this out. You need to look in your theme folder and maybe in your plugins to see if and where ACF is included.

    What you can do from here basically depends on how the theme/plugin that it’s included in was built. Depending on that, which would be extremely difficult for anyone to say, you can try to update ACF manually or remove it from the theme and install it just like any other plugin. But like I said, there’s no way of telling and really no way of really explaining it. There are just too many variables. And updating ACF may cause other errors, again, depending on how the theme/plugin it’s included in was built.

    Most JS errors like the one you describe are caused by conflicts with other plugins. This conflict may or may not be resolved by updating ACF. You can determine what ACF might be conflicting with by disabling other plugins on the site to see which one causes the error to be corrected.

    I would start by creating a duplicate of the site in a testing environment so that I could work on the issue without effecting the live site simply because it’s impossible to know what you’ll need to do to correct the problem.

  • Thank you John.

    One thing I’ve noticed is that the following embedded php code in relationship.php doesn’t seem to execute/parse:

    $this->l10n = array(
     'max'     => __("Maximum values reached ( {max} values )",'acf'),
     'tmpl_li' => '
                   <li>
                     <a href="#" data-post_id="<%= post_id %>"><%= title %><span class="acf-button-remove"></span></a>
                   <input type="hidden" name="<%= name %>[]" value="<%= post_id %>" />
                  </li>
                 '
    );

    The result when run and viewed (via the chrome console) the result is the following, which still has the literal variables, not the values I would expect:

    	// new vars
    	acf.o = {"post_id":425,"nonce":"25e1faa643","admin_url":"http:\/\/stage.media.foodlandontario.ca\/wp-admin\/","ajaxurl":"http:\/\/stage.media.foodlandontario.ca\/wp-admin\/admin-ajax.php","wp_version":"4.8.1"};
    	acf.l10n = {"core":{"expand_details":"Expand Details","collapse_details":"Collapse Details"},"validation":{"error":"Validation Failed. One or more fields below are required."},"image":{"select":"Select Image","edit":"Edit Image","update":"Update Image","uploadedTo":"uploaded to this post"},"file":{"select":"Select File","edit":"Edit File","update":"Update File","uploadedTo":"uploaded to this post"},"relationship":{"max":"Maximum values reached ( {max} values )","tmpl_li":"\n\t\t\t\t\t\t\t<li>\n\t\t\t\t\t\t\t\t<a href=\"#\" data-post_id=\"<%= post_id %>\"><%= title %><span class=\"acf-button-remove\"><\/span><\/a>\n\t\t\t\t\t\t\t\t<input type=\"hidden\" name=\"<%= name %>[]\" value=\"<%= post_id %>\" \/>\n\t\t\t\t\t\t\t<\/li>\n\t\t\t\t\t\t\t"},"google_map":{"locating":"Locating","browser_support":"Sorry, this browser does not support geolocation"},"date_picker":{"closeText":"Done","currentText":"Today","monthNames":["January","February","March","April","May","June","July","August","September","October","November","December"],"monthNamesShort":["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],"monthStatus":"Show a different month","dayNames":["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],"dayNamesShort":["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],"dayNamesMin":["S","M","T","W","T","F","S"],"isRTL":false}};
    	acf.fields.wysiwyg.toolbars = {"full":{"theme_advanced_buttons1":"bold,italic,strikethrough,bullist,numlist,blockquote,hr,alignleft,aligncenter,alignright,link,unlink,wp_more,spellchecker,fullscreen,wp_adv","theme_advanced_buttons2":"formatselect,underline,alignjustify,forecolor,pastetext,removeformat,charmap,outdent,indent,undo,redo,wp_help,code","theme_advanced_buttons3":"","theme_advanced_buttons4":""},"basic":{"theme_advanced_buttons1":"bold,italic,underline,blockquote,strikethrough,bullist,numlist,alignleft,aligncenter,alignright,undo,redo,link,unlink,fullscreen"}};

    Thoughts?

  • I couldn’t tell you if this has anything to do with the error or not, but the code you mention is run and you can see the result in part of that JSON string

    ... "relationship":{"max":"Maximum values reached ( {max} values )","tmpl_li":"\n\t\t\t\t\t\t\t<li>\n\t\t\t\t\t\t\t\t<a href=\"#\" data-post_id=\"<%= post_id %>\"><%= title %><span class=\"acf-button-remove\"><\/span><\/a>\n\t\t\t\t\t\t\t\t<input type=\"hidden\" name=\"<%= name %>[]\" value=\"<%= post_id %>\" \/>\n\t\t\t\t\t\t\t<\/li>\n\t\t\t\t\t\t\t"} ...

    I would be looking for other JS errors that happen prior to the error in ACF.

  • Sorry, not 100% sure I follow you. We agree that the code like:

    `post_id=\”<%= post_id %>\”>

    should not be visible, but rather should be parsed – something like:

    post_id=\"45\">

    Meaning an error is occurring before this, and that I’m to check for that error(s)? Just double checking…

  • You need to update ACF. The PHP code you posted in no longer part of ACF4

    
    $this->l10n = array(
     'max'     => __("Maximum values reached ( {max} values )",'acf'),
     'tmpl_li' => '
                   <li>
                     <a href="#" data-post_id="<%= post_id %>"><%= title %><span class="acf-button-remove"></span></a>
                   <input type="hidden" name="<%= name %>[]" value="<%= post_id %>" />
                  </li>
                 '
    );
    
  • I have directory with 3 folders, which includes repeater. I assume the original developer bought the pro version, but have no way to prove it as I can’t contact of the person. How do I go about upgrading?

    1. acf-options-page
    2. acf-repeater
    3. advanced-custom-fields
  • You are using ACF4. You should be able to download the latest version of the plugin from the WP repo and replace the folder advanced-custom-fields with the new version. I’m not sure about the repeater and options page plugins, but I’d update ACF first and see if that corrects the issue your seeing.

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

The topic ‘post_id is not defined’ is closed to new replies.