Hi Man, I think there is a syntax error in your code. You should check whether there is a field or not (as you’ve done) but you should even check if there are rows
. Also when you echo a sub_field sticking it in a variable use
get_the_sub_field()
. So try the code below and let me know if that’s what you’re looking for 🙂
<div class="entry-content"> <?php the_content(); ?> <?php wp_link_pages( array( 'before' => '<div class="page-links">' . __( 'Pages:', 'pictorico' ), 'after' => '</div>', ) ); ?> <?php if(get_field('spalten')): ?> <?php while(have_rows('spalten')): the_row(); ?> <div class="columns"> <div class="col-left"><?php $wysiwyg = get_the_sub_field('linke_spalte', false, false); echo apply_filters('the_content', $wysiwyg); ?></div> <div class="col-right"><?php $wysiwyg = get_the_sub_field('rechte_spalte', false, false); echo apply_filters('the_content', $wysiwyg); ?></div> </div> <?php endwhile; ?> <?php endif; ?> </div><!-- .entry-content -->
Also you probably need to make sure there are posts to display so at the very top of it you should do something like:
<?php if(have_posts() ) { while ( have_posts() ) { the_post(); ?>
No, I’m sorry if I was unclear. The problem is that the *content* of the post is being displayed where **get_field** is called. For example, on attachment pages, the attachment content appears before the content of the field:
<audio><!-- attachment audio stuff... --></audio>
<p>WYSIWYG content from get field</p>
The entire **<audio/>** tag should not appear there, it is not called in the code and is not in the WYSIWYG content of the field.
This error only appears with WYSIWYG fields.
Actually, I managed to solve this problem in another way. I post here the solution in case somebody else is interested in the answer:
1) I created a Wysiwyg Editor field.
2) Added the field normally in my php file.
3) In the post editor, I used the normal wordpress “more” tag, which automatically inserts the shortcode <!–more–> inside my content and creates two paragraphs automatically, one before and one after the shortcode.
4) In my Jquery file, I wrote this code:
$('p').html(function(_, text) {
return text.replace('<!--more-->', '<a href="#" class="read_more">read more</a>' );
});
That’s it, basically. With that link and that class I can manipulate the link as I want.
Hey Elliot,
strangely this is not working for me.
I’m using the WYSIWYG editor within the Flexible Content field and trying to display a Jetpack Contact Form with no success.
I tried 2 versions of your suggestion for testing and none of them worked.
First attempt:
if( have_rows('flexible_content') ):
while ( have_rows('flexible_content') ) : the_row();
if( get_row_layout() == 'full_column' ):
$fullWidth = get_sub_field('full_width');
echo apply_filters('the_content', $fullWidth);
endif;
endwhile;
endif;
Second attempt:
<?php if( have_rows('flexible_content') ):
while ( have_rows('flexible_content') ) : the_row();
if( get_row_layout() == 'two_columns' ):
$half1 = get_sub_field('half_1');
$half2 = get_sub_field('half_2'); ?>
<div class="block group">
<div class="col1-2"><?php echo $half1 ? apply_filters('the_content', $half1) : ' '; ?></div>
<div class="col1-2 last"><?php echo $half2 ? apply_filters('the_content', $half2) : ' '; ?></div>
</div>
<?php endif;
endwhile;
endif; ?>
If you can take glance:
http://texeurop.prompt-dev.com/contact/
Versions running:
WP 4.1
ACF 5.1.8
hope i understand you right. (i had done core search ability by a workaround)
if you dont use the normal content field of WP, then you could try something like that:
function my_acf_update_text($post_id) {
if( have_rows('my_custominhalt') ):
// loop through the rows of data
while ( have_rows('my_custominhalt') ) : the_row();
$my_search="";
if( get_row_layout() == 'text-block' ){
$my_subtitle = get_sub_field('my_subtitle');
$my_content = get_sub_field('my_text_content');
$my_search = '<h3>'.$my_subtitle.'</h3><p>'.$my_content.'</p>';
}
if( get_row_layout() == 'text-image-block' ){
$my_subtitle = get_sub_field('my_subtitle');
$my_content = get_sub_field('my_imagetext');
$my_search = '<h3>'.$my_subtitle.'</h3><p>'.$my_content.'</p>';
}
$my_search_full = $my_search_full.' '.$my_search;
endwhile;
endif;
// update post with the post_content created from
$my_post = array('ID'=> $post_id,'post_content' => $my_search_full);
remove_action('save_post', 'my_acf_update_text');
wp_update_post( $my_post );
add_action('save_post', 'my_acf_update_text');
}
add_action('save_post', 'my_acf_update_text');
place it into your plugin, or functions.php
what it does : it create a action that loop through all flexible fields with text, and save them to post_content. thanks to that i am able to search content by core function.
hope that help you too (of course you need to adjust it to fit your needs)
be careful, it overwrite anything inside post_content(core-wysiwyg of WP)
you also need to re-save every post before it works, because only after save content is inserted into post_content
if you need core-wysiwyg, then create a additional field and save the loop into that field. basically it would be easier to search only inside a single field instead of a repeater/flexible field
have you same problem (shortcode that did not work) with Contact Form 7 or some other plugin that use shortcode?
because i cant confirm any problem with ACF and shortcode. (not inside wysiwyg, nor inside textarea or textbox)
if you have same problem with Contact Form 7 too, then problem is maybe a filter, your template, or an other plugin that you use.
if Contact Form 7 has not the same problem then your slider-plugin/shortcode is the problem.
or maybe this help:
$slider = get_field('page_slider',$page->ID, false);
And please check your console log for any JS errors on the page. This could explain why the WYSIWYG field is no longer working
hi
thank you for this suggestion, but it doesn´t work for me
<div class="entry-content">
<?php the_content(); ?>
<?php
wp_link_pages( array(
'before' => '<div class="page-links">' . __( 'Pages:', 'pictorico' ),
'after' => '</div>',
) );
?>
<?php if(get_field('spalten')): ?>
<?php while(has_sub_field('spalten')): ?>
<div class="columns">
<div class="col-left"><?php
$wysiwyg = the_sub_field('linke_spalte', false, false);
echo apply_filters('the_content', $wysiwyg);
?></div>
<div class="col-right"><?php
$wysiwyg = the_sub_field('rechte_spalte', false, false);
echo apply_filters('the_content', $wysiwyg);
?></div>
</div>
<?php endwhile; ?>
<?php endif; ?>
</div><!-- .entry-content -->
http://wp.bieblwerk.de/agentur/
I´m using a repeater field, are ther any other options?
Thank you very much
Hi @rpk
It sounds like the issue is coming from the format_value filter. This filter is used to allow each field type (and functions.php) to modify the value based on the field.
This explains why the field value is returned for non WYSIWYG fields.
Can you confirm that you have no format_value filter code in your functions.php file which could be clearing the $value?
Next, try adding 2 false parameters to your code like so:
$test = get_field( 'pro_description', false, false );
Does this allowed the WYSIWYG field to return it’s value?
Hi @healthfirst
The functions.php file is used to hook into both the front and back ends of the website to customize many parts.
the_content
is a filter which should only be used on the front end of the website. As in, shown in a page template, not shown in the wp-admin.
Can you please confirm what version of ACF you are using?
You mentioned ‘Tab_content’ is referring to the tab content (WYSIWYG) in the Admin folder.
So am I right to assume the problem in the backend (wp-admin)?
I don’t know what <?php build_i_world_map(1); ?>
is but it shouldn’t be related to this issue.
The original code should only modify the WYSIWYG value on the front end of the website (page template), but should not ever have changed the value in the backend. The backend should have had no changes from the code.
If you are running ACF v4.x.x, then this is the wrong code. Please use format_value_for_api
, not format_value
and this could explain why it is being run in the backend.
I have it set to “true.” Those screen shots are all I can see when I inspect the element and view the console.
It’s sporadic. It was showing the true rich text editor early this evening. But now it is not showing up again. It’s very on/off throughout the day.
Update:
I have confirmed with my host that nothing has changed on their end recently. I have seen hosts change security settings which cause files/ajax not to run properly. My site is working fine, for now. One user said that the edit post page in the Admin looked wrong at first (WYSIWYG showing only code view and no toolbars, and the relationship field spinner only showing), but after 20 seconds then it loaded something and looked fine.
Would an upgrade to version 5 maybe fix this?
Hi guys
Please note that the filter has changed in ACF PRO. Please change format_value_for_api
to format_value
:
<?php
add_filter('acf/format_value/type=wysiwyg', 'format_value_wysiwyg', 10, 3);
function format_value_wysiwyg( $value, $post_id, $field ) {
$value = apply_filters( 'the_content', $value );
return $value;
}
?>
Thanks. After turning debug on, I see this in the browser console. I’m not sure I see a connection between what is happening, and what those errors are.
I attached another image showing how the WYSIWYG field is displaying now.
Will this fix also work for ACF version 4.3.9?
My WYSIWYG fields are only showing the code view of the field, and not showing the toolbars or normal text editor.
I also get this error in the console:
Uncaught TypeError: undefined is not a function
input.min.js?ver=4.3.9:1
Elliot has pointed me in this direction before for a similar issue.
If you pass the custom field through the_content filter, it should then kick in.
Here is the example provided to me before:
$value = get_field('wysiwyg_field_name');
echo apply_filters('the_content', $value);
This looks to be more a question about editing TinyMCE, the editor that powers the WordPress WYSIWYG.
There are a number of plugins that can do what you need, here is one as a starting point:
https://wordpress.org/plugins/tinymce-advanced/
There’s an updated version of the plugin on Github which you need to install to get v5 support. It didn’t automatically come up as a plugin update in my WordPress admin, I had to do it manually.
Ok i think i figured things out.
function last_paragraph( $content ){
if ( is_page( 222 ) ) {
return preg_replace('/[\s\S]*\K(<p>)/', '<p class="mytrail">', $content, 1);
}
}
add_filter('acf_the_content', 'last_paragraph');
I’ve set the function only to a certain page and on that page it targets only acf fields ( which are in my case only text fields, text areas and wysiwyg fields). Text fields and text areas don’t have any wrapping p tags therefor only wysiwyg fields are targeted. And with that small function it is possible that the user is able to add more paragraphs in each wysiwyg field and still the class is set on the last paragraph of each wysiwyg field.
Rather than attempt this with ACF, I would do this with CSS. You can wrap the field in a div, like this:
<div class="my-wysiwyg">
<?php the_field('my_wysiwyg');?>
</div>
Then just apply the styling to the last <p> tag with CSS:
.my-wysiwyg p:last-child {
font-size: 30px;
}
Does that help?
I would also like to know how to edit the wysiwyg, but not only the toolbar!
what i know is:
because acf not use the default tinymce of wp-core (or at least use a own init method) some solutions that work with core didnt work with acf-wysiwyg fields.
Additional/similar Topics to this thread (with no answer!)
http://support.advancedcustomfields.com/forums/topic/wysiwyg-editor-acf-is-missing-general-wp-editor-functionality/
http://support.advancedcustomfields.com/forums/topic/acf-pro-wysiwyg-not-getting-changed-default-settings/
Yeah this is a major limitation. It’s stopped me from using repeater with WYSIWYG. I really hope there can be a solution at some point. Next time a have a bit a break from work I’ll take a look at this issue in detail.
is it possible to edit other settings too?
i had a hook that works for the default wysiwyg.
but not for the acf_wysiwyg-fields. (it looks like my hook is not fully executed)
add_action( 'wp_tiny_mce_init', function () {
?>
<script>
function editShortcut_tiny_mce_init(ed) {
ed.on('init', function () {
// Note these lists may not be complete & that other tinymce plugins can add their own shortcuts anyway.
var ctrls = [ 'u', '1', '2', '3', '4', '5', '6', '7', '8', '9', 's', 'k', 'Alt+F', 'P' ];
var modKeys = [ 'c', 'r', 'l', 'j', 'q', 'u', 'o', 'n', 's', 'm', 'z', 't', 'd', 'h', 'o', 'x', 'a', 'w' ];
// Overwrite shortcuts with no-op function. Key sequences will still be captured.
for (var i = 0; i < ctrls.length; i++ ) {
this.addShortcut('ctrl+' + ctrls[i], '', function () {});
}
for (var i = 0; i < modKeys.length; i++ ) {
this.addShortcut('alt+shift+' + modKeys[i], '', function () {});
}
});
}
</script>
<?php
});
function my_acf_editor( $mceInit, $editor_id ) {
$mceInit['setup'] = 'editShortcut_tiny_mce_init';
// What goes into the 'formatselect' list
$mceInit['block_formats'] = 'Header 3=h3;Header 4=h4;Header 5=h5;Paragraph=p;Code=code';
$mceInit['paste_word_valid_elements'] = '-strong/b,-em/i,-p,-ol,-ul,-li,-h3,-h4,-h5,-h6,-p,-table[width],-tr,-td[colspan|rowspan|width],-th,-thead,-tfoot,-tbody,-a[href|name],br,del';
$mceInit['paste_strip_class_attributes'] = 'all';
$mceInit['toolbar1'] = 'bold,italic,formatselect,bullist,numlist,blockquote,link,unlink,undo,redo';
return $mceInit;
}
add_filter('tiny_mce_before_init', 'my_acf_editor')
i need a solution that works inside function.php or better, inside my custom plugin.
can anyone help me? please.
my aim is: to have a verry simple wysiwyg that only allow things defined by me.
only edit toolbar is not enough, because the user can avoid these restrictions with shortkeys and/or copy&paste from word.
Fixed this by creating my own custom acf field. the new custom field gets a field name and does get_field(“myfieldname”) on the render_field() function. This shows any field entered to render into the edit section. I could have a wysiwyg show up as long fancy instructions for the user to read. Better way to work up a sign up form with fancy text or a popup terms and agreement. the only thing left now is to hide the labels which I can easily do with css.
function render_field( $field ) {
$id = $field['field_idname'];
if(get_field($id,'options')){
echo get_field($id,'options');
}
}
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.