444 posts
  • Bought between 1 and 9 items
  • Exclusive Author
  • Has been a member for 4-5 years
  • United Kingdom
TahaH-Studio says

hey guys.

Is there any way to insert a extra column in the wp_posts table or any other alternative way to allow me to insert an extra parameter in the wp_insert_post function.

Here is an example of what I need to do. The extraOption is what i need to add.
global $user_ID;
$new_post = array(
    'post_title' => 'Post Title',
    'post_content' => 'Post Content...',
    'post_author' => $user_ID,
    'extraOption' => 'Some extra content'
);
$post_id = wp_insert_post($new_post);

Thanks in advance
Taha

659 posts
  • Bought between 10 and 49 items
  • Exclusive Author
  • Has been a member for 5-6 years
  • Referred between 50 and 99 users
  • Sold between 10 000 and 50 000 dollars
  • United States
luckykind says

what are you trying to do? As in what are you using that extra content for… and where is it coming from?

444 posts
  • Bought between 1 and 9 items
  • Exclusive Author
  • Has been a member for 4-5 years
  • United Kingdom
TahaH-Studio says

The extra content will be to hold an img url. I could add it as meta into the post but the thing that i wouldn’t be able to insert it programmatically with the post when I insert it using wp_insert_post function. The whole idea is the ability to insert that img url outside the dashboard with the post.

366 posts
  • Elite Author
  • Sold between 100 000 and 250 000 dollars
  • Has been a member for 4-5 years
  • New Zealand
  • Referred between 10 and 49 users
  • Bought between 10 and 49 items
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
PixelStores says

Ok, i think i understand on what your trying to do. You want to receive custom post meta data commonly known as custom fields into your post.

I had ago at the code and it might be your solution.

global $user_ID;
$thumb = get_post_meta($post->ID, 'Thumbnail', $single = true);
$new_post = array(
    'post_title' => 'Post Title',
    'post_content' => 'Post Content...',
    'post_author' => $user_ID,
    'extraOption' => $thumb,

);
$post_id = wp_insert_post($new_post);

You can set the “get_post_meta” function as an array and in simple terms, sets your “extraOption” value as the array.

The above code looks for the custom field “Thumbnail”. If you want to show the value of the custom field use this:

<?php $thumb = get_post_meta($post?>ID, 'Thumbnail', $single = true); ?>

Let me know how it goes. Matt

659 posts
  • Bought between 10 and 49 items
  • Exclusive Author
  • Has been a member for 5-6 years
  • Referred between 50 and 99 users
  • Sold between 10 000 and 50 000 dollars
  • United States
luckykind says
global $user_ID;
$new_post = array(
    'post_title' => 'Post Title',
    'post_content' => 'Post Content...',
    'post_author' => $user_ID,
);
$post_id = wp_insert_post($new_post);

add_post_meta($post_id, 'my_url', 'http://myurl.com');

I’m guessing this is what you’re after…

444 posts
  • Bought between 1 and 9 items
  • Exclusive Author
  • Has been a member for 4-5 years
  • United Kingdom
TahaH-Studio says

Thank you guys, I got it working :D

by
by
by
by
by
by