Support

Account

Home Forums General Issues Populate WYSIWYG field with post object

Solving

Populate WYSIWYG field with post object

  • Hello,

    So, something I am having a difficult time with right now is trying to populate some fields with data from a post object selection. I am putting together a proposal system, and need the ability to store “canned” responses for items but have the ability to edit them to be more custom for certain scenarios.

    Scenario: I have 4 custom post types.
    Setup: 1 of my custom post types uses a flexible content field, within this field I have a ACF Gravity Forms field, Post Object field (pulling in posts from another custom post type), a WYSIWYG field and finally a text field.
    Issue: After choosing a post from the Post Object field, I need to populate my blank WYSIWYG field with the content from that post.

    After some digging online someone pointed me to this WP function:

    add_filter( 'default_content', 'my_editor_content' );
    function my_editor_content( $content ) {
    	$content = 'DEFAULT CONTENT HERE.';
    	return $content;
    }

    Which works for my default WP editor, but I am unsure if I can use this function to translate to my ACF field pulling in the data from the post object.

    I found this link: http://www.advancedcustomfields.com/resources/filters/acf-fields-post_object-result/ but again, not certain if that applies to what I am trying to achieve here.

    Any help would be greatly appreciated. Been tackling this issue on and off for a while now with no luck. Attached is a screen grab of the fields.

  • Hi @dalbeck

    You can achieve this by writing some custom jQuery / PHP. If you are not familiar with writing custom jQuery / AJAX / PHP scripts, you may need to contract a developer to do this for you.

    Upon ‘change’ of the post object field, you will need to perform a custom AJAX query to get the selected post’s content.

    With the post’s content returned, you will then need to use JS to update the WYSIWYG field. This is not the easiest task, but is possible by reading over the js/input.js file and scrolling down to the WYSIWYG section. You will see many tinymce functions which you can use to update the value.

    Thanks
    E

  • This reply has been marked as private.
  • Hi @dalbeck

    Sorry, but I don’t offer freelance services. Perhaps a freelance job board could be a good place to post the project?

    Good luck.

    Thanks
    E

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

The topic ‘Populate WYSIWYG field with post object’ is closed to new replies.