How to make search and replace in content through php

From the documentation of WP All Import, the pmxi_saved_post action takes one parameter, $id, which is “the ID of the post/page/Custom Post Type that was just created.” So, your post_saved() callback should look like this: add_action(‘pmxi_saved_post’, ‘wpse246838_post_saved’, 10, 1); function wpse246838_post_saved( $id ) { $my_post = array( “ID” => $id, “post_content” => “1”, ); wp_update_post( … Read more

Float images in content

You need to setup CSS settings for alignleft class of your theme: .alignleft, img.alignleft { /* … */ display: inline; float: left; /* … */ } And you need to add editor stylesheet where the same CSS will be presented. Create editor-style.css file in your theme, put content CSS settings there and call add_editor_style(); from … Read more

How to add content at the end of posts?

You can simply use get_field that returns the field instead of the_field that echo it. function custom_content_filter_the_content( $content ) { if ( function_exists(‘get_field’) ) { $content .= ‘<span class=”custom_fds”>’ . get_field(‘field1’) . ‘</span>’; } return $content; } add_filter( ‘the_content’, ‘custom_content_filter_the_content’ );

wp_insert_post -> post_content not showing

OK, SO this is what I found out, the data <object>…</object> was the culprit. WordPress sanitizes the input before committing to the database. Other non allowed tags include <embed>…</embed> I’ve seen this solution online $postData = array( … ‘filter’=>true … ); However, some people say that’s a security flaw. I dug a little deeper and … Read more

Exclude posts with empty post_content in wp_query

This isn’t possible with a standard WP query, and you’ll have to leverage the use of posts_where before the WP_Query is called. function the_dramatist_filter_where($where=””){ $where .= ” AND trim(coalesce(post_content, ”)) <>””; return $where; } In the above, we’re simply only selecting posts where the column post_content isn’t empty. Then add the filter. add_filter(‘posts_where’, ‘the_dramatist_filter_where’); Now … Read more

Conditionally set post_content in wp_insert_post

I can’t help but think I am missing something but what seems like the obvious answer is to alter your $create_pages array: $create_pages = array( ‘one’ => ‘content for one’, ‘two’ => ‘content for two’, ‘three’ => ‘content for three’ ); foreach ($create_pages as $title => $content) { $add_pages = array( ‘post_title’ => $title, ‘post_content’ … Read more

Check if page/post has any anchors that link to an image jpg/gif/png

This method has worked in the past for checking if a shortcode exists on a page. You will have to test it and see if it fires in time to enqueue the javascript> add_filter(‘the_posts’, ‘c3_image_check’); function c3_image_check($posts){ if (empty($posts)) return $posts; $img_found = false; foreach ($posts as $post) { if (stripos($post->post_content, ‘<img src=”https://wordpress.stackexchange.com/questions/53585/)) { $img_found … Read more

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