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

Contact Form 7 to featured image

Thanks @Judd Franklin for the directions. I was also missing $submission->uploaded_files();. Here is the working code for those who are looking for the same answer: function image_form_to_featured_image( $contact_form ) { $submission = WPCF7_Submission::get_instance(); $posted_data = $submission->get_posted_data(); // Creating a new post with contact form values $args = array( ‘post_type’ => ‘projects’, ‘post_status’=> ‘draft’, ‘post_title’=> wp_strip_all_tags( … Read more

wp_insert_post returns int(0)

According to the notes on the codex wp_insert_post() post_title and post_content are required If you want the content to be empty, you can write your wp_insert_post args array thus: $postID = wp_insert_post(array( “post_title” => $name, “post_status” => “publish”, “post_content => ” “, “post_type” => “mycustomposttype”, ), true);

wp_insert_post insert a post but return 0

I found the answer. Actually I was passing the template in the wp_insert_post. When I remove that parameter it returns the post ID. And with that post ID I used add_post_meta( $page_id, ‘_wp_page_template’, ‘tpl-favourites.php’ ); to set the template for that page. It is a common technique. I have just dig the code of a … Read more

Visual Editor – Colorize Shortcodes

Managed to get a working solution. What you need: TinyMCE Advanced plugin What you should do: Customize the Visual Blocks Plugin that comes with the TinyMCE plugin and add css classes for each element you would to highlight (just loop through all p elements and parse the innerHTML and check if it contains your specific … Read more

Replace string with post_name on sidebar

Your code looks well and considerations are correct. In order to achieve your goal, I’d collect HTML and wrap it up like this: Instead of calling <?php dynamic_sidebar($sidebar_id); ?> use <?php dynamic_sidebar_replaced($sidebar_id); ?> with a function (add it to functions.php) below: function dynamic_sidebar_replaced($sidebar_id) { if (is_single()) { // Optionally, to ensure you’re at the single … Read more

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