Replace post’s “the_content” with ACF value

Instead of updating the post’s content, you can filter it using the the_content filter. add_filter( ‘the_content’, ‘wpse241388_use_acf_field’ ); function wpse241388_use_acf_field( $content ) { return get_field( ‘article_text’ ); } Update To apply to only your article post type: add_filter( ‘the_content’, ‘wpse241388_use_acf_field’ ); function wpse241388_use_acf_field( $content ) { if ( is_singular( ‘article’ ) ) { $content = … Read more

Wrap First Character after in a tag

The major issue is just that you have a positive lookbehind but no capture group so \1 or $1 isn’t a usable variable. Fix your regex to provide the capture group: ‘/(?<=\<\/h3\>\n<p>)(.)/’ then reference as $1. ob_start();?> <h3>Heading</h3> <p>Paragraph</p> <p>Paragraph2</p> <?php $search = ob_get_clean(); $result = preg_replace( ‘/(?<=\<\/h3\>\n<p>)(.)/’, ‘<span class=”dropcap”>$1</span>’, $search );

the_content filter – checking the post

You’ll need to rely on the global post variable, or get_post(), which is essentially the same thing. add_filter( ‘the_content’, function( $content ) { $post = get_post(); if ( in_the_loop() && has_category( 123, $post ) ) { // etc. } return $content; } ); I included a check for in_the_loop(), because the the_content filter is commonly … Read more

Output 2 items within the Loop

Easy using WP query (get to know it…) <ul> <?php $recentPosts = new WP_Query(); $recentPosts->query(‘showposts=2’); // SET AMOUNT HERE ?> <?php while ($recentPosts->have_posts()) : $recentPosts->the_post(); ?> <li><div class=”slide”><?php the_content(); ?></div></li> <?php endwhile; ?> </ul> Hope this helps. Let me know if you encounter any issuse. EDIT 1: * explenation – just added a small conditional … Read more

Editing

Yes, it is possible. You can use the_content hook and assign your own filter to this hook. Then you should (that is the part when things get a little bit messy) parse and replace content of that post. So for example you can do it like so: function my_the_content_filter($content) { $content = str_replace(‘<h2 ‘, ‘<img … Read more

What is the proper way to get contents of a page?

A few notes before I start NEVER EVER use php shortcodes, they are bad, confusing and not supported by default on some servers. IMHO, they should have never made it into PHP in the first place. WordPress Standards (which doesn’t mean much) also “prohibits” the use of shorttags. Use proper php tags and forget that … Read more

Output the_title() inside the_content()

You could achieve that with a filter on the_content: function my_the_content_filter( $content ) { global $post; if( ‘testimonial’ == $post->post_type ) $content .= ‘ <em>’ . $post->post_title . ‘</em>’; return $content; } add_filter( ‘the_content’, ‘my_the_content_filter’, 0 );

Getting first 20 words without excerpt

Use wp_trim_words() wp_trim_words( get_the_content(), 20 ) As you’re outside the main loop wp_trim_words( $recent[ ‘post_content’ ], 20 ) If you want to apply the same filters as to the_content() in the main loop wp_trim_words( apply_filters( ‘the_content’, $recent[ ‘post_content’ ] ), 20 )

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)