insert image with custom post type

Your current code should be correctly creating the post inside your Products post type. You’re missing the bit that updates the post meta holding the image. Assuming the meta_key is product_image, then running this on success should do: update_post_meta( $pid, ‘product_image’, $attachment_id ); on a side note: don’t forget to run wp_generate_attachment_metadata and wp_update_attachment_metadata after … Read more

Adding post date will not insert new post

Your code is correct. I have tested it and it works. I think what you are missing, and what I have missed while testing (banged my head against the wall for this mistake) is the fact that these posts do not show up at the top of your post list. Remember, by default, that posts … Read more

oEmbded with wp_insert_post() [embedly]

Read up on Embeds. To trigger an embed use wp_oembed_get($url). In general the url needs to be on it’s own line with a space below and above when inside the_content. wp_insert_post() has nothing to do with embeds as the embed HTML is usually generated when passed through the_content filter. To add support for non-oEmbed sites … Read more

Get Post ID after front end post submission

wp_insert_post() returns either one of three things the newly created post’s ID a WP_Error object if $wp_error is set to true if an error occured during post insertion in which case the post is not inserted 0 if $wp_error is set to false (default) if an error occured during post insertion in which case the … Read more

Fatal error: Call to undefined function wp_insert_post()

If you’d like to use WordPress functions inside your naked PHP file, you’ll have to load the WordPress environment: require_once ‘/path/to/wp-load.php’; That said it’s best practice to NOT handle things via separate PHP files like that outside of WordPress, but use a plugin instead and fire your code on an appropriate action. You can use … Read more

Create one-use post dynamically, add to main query, do not insert post (user profile view)

From what I understand you are trying to change the permalink structure of the user, so instead of showing yoursite.com/author/yourusername it will show yoursite/profile/yourusername? You can add a rewrite rule to the permalink structure to make that change: function yourdomain_user_rewrite() { global $wp_rewrite; $wp_rewrite->author_base=”profile”; $wp_rewrite->author_structure=”https://wordpress.stackexchange.com/” . $wp_rewrite->author_base . ‘/%author%’; } add_action( ‘init’, ‘yourdomain_user_rewrite’ ); Then … Read more

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