Create posts by any logged in users
Create posts by any logged in users
Create posts by any logged in users
I’ve recently done a batch import of about 200 posts, with 5 taxonomies attached to them and each of the posts a few terms. It took about 5-10 seconds to do the whole batch. So no, it shouldn’t be this slow.
Thanks for your answers! Maybe I was a bit unclear, but I don’t use ACF, it is just a field that comes with the theme. However, this question and answers helped to find the problem: https://stackoverflow.com/questions/34018588/wordpress-add-post-meta-data-doesnt-display-on-page-until-post-is-manually My WP metadata table entry was incomplete after creating a post programatically, the theme required another field. Saving the … Read more
The reason for that is the save_post loop. When you call wp_insert_post, it triggers save_post and thus inserts the student meta. what you can do is, to check if the post type is correct while inserting the meta. like: add_action( ‘save_post’, ‘save_student_meta’, 10, 2 ); function save_student_meta( $post_id, $post ) { if ( ‘student’ !== … Read more
Here’s an updated version of your code: add_action(‘save_post’, array($this, ‘save_post_type_example_meta_boxes’)); function save_post_type_example_meta_boxes($post_id) ………. if (…) { $new_custom_post = array( ‘post_title’ => $title, ‘post_content’ => ”, ‘post_status’ => ‘publish’, ‘post_author’ => 1, ‘post_type’ => ‘custom_post_type’, ‘meta_input’ => array( ‘meta_1’ => ‘X’, ‘parent_post_id’ => $post_id, ), ); // Prevent this action from running twice. remove_action( ‘save_post’, [ … Read more
So I ended up just adding the meta after inserting the post, which doesn’t give any error. It bypasses the problem without explaining it though… $postarr = array( ‘post_title’ => $link[‘caption’], ‘post_type’ => ‘ct_external_link’, ‘post_status’ => ‘publish’, ‘post_excerpt’ => $link[‘caption’], ); $external_link_id = wp_insert_post($postarr); if( !empty($external_link_id) ) { add_post_meta($external_link_id, ‘ct_external_link_url’, $doc[‘file’], true); if( isset($doc[‘hide’]) ) … Read more
Hello and thanks for all who read this and commented. Apparently, the query didn’t return any rows because BOTH FIELDS need to be present for the query to run correctly. The secondary meta parameter “message_read_by” didn’t exist so I just needed to insert with no value. Problem solved.
get_page_by_title() not working as expected
wp_insert_post not adding taxonomy (using wp_set_object_terms)
AH! https://permalinkmanager.pro/docs/tutorials/how-to-remove-numbers-2-3-appended-to-the-permalinks/ So the automatic slug creation of -2, -3, ..etc is done by core in order to make slugs unique. But I knew there was a way to change the permalink and not the slug. I just couldn’t find code anywhere to do this so I resorted to using this premium plugin. global $permalink_manager_uris; … Read more