Using table lock with wp_insert_post?

Firstly, your question indicates that your plugin sometimes runs over 5 min, don’t you get script timeouts? 5 min is a very long runtime… How many posts are you adding and what’s your server environment? Back to the problem… May I suggest another solution? Simply set an option that you’re doing something, and deactivate it … Read more

Is there a faster way than wp_insert_post to add content to a blog

You can access the database with an INSERT statement and add multiple rows at once. Something like this pseudo-code: INSERT INTO $wpdb->posts ( `post_author`, `post_date`, `post_date_gmt`, `post_content`, `post_title`, `post_status`, `post_name`, `post_modified`, `guid`, `post_type`, `post_mime_type` ) VALUES ( $user_id, $current_date,$current_date_gmt, $content1 ), ( $user_id, $current_date,$current_date_gmt, $content2 ), ( $user_id, $current_date,$current_date_gmt, $content3 ) ; Make sure to … Read more

WP_INSERT_POST issue on WordPress Multisite

The hook declaration takes 6 parameters, yet none is in your function’s definition. Also, before calling the hook wpmu_new_blog, WP does a restore_current_blog(), so it’s safe to assume that we have to switch to the destination blog before inserting content. add_action( ‘wpmu_new_blog’, ‘new_blog_wpse_115724’, 10, 6 ); function new_blog_wpse_115724( $blog_id, $user_id, $domain, $path, $site_id, $meta ) … 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

Automatically insert php function into post $the_content

I’m sure you want to use the_content filter instead of the default_content filter (already mentioned by @jgraup) because what happens if the generated HTML changes? Then you’re stuck with it in your content. It’s better to add it dynamically. Here’s one suggestion: add_filter( ‘the_content’, function( $content) { if( ! in_the_loop() ) return $content; if( ‘property’ … Read more

Created pages not showing up in ‘All Pages’ list

The problem was actually the pages having “no language” and WPML seems to hate this. So I just deleted all those pages and re-inserted them with the proper WPML language attributes: // (…) // Create the page $customPage[‘id’] = wp_insert_post( $pageParams ); // Check if WPML parameters are needed if (has_action(‘wpml_set_element_language_details’)) { // Set WPML … Read more

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