444 posts
  • Has been part of the Envato Community for over 5 years
  • Has collected 1+ items on Envato Market
  • Sells items exclusively on Envato Market
  • Located in 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
  • Has been part of the Envato Community for over 6 years
  • Has referred 50+ members
  • Has collected 10+ items on Envato Market
  • Sells items exclusively on Envato Market
+2 more
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
  • Has been part of the Envato Community for over 5 years
  • Has collected 1+ items on Envato Market
  • Sells items exclusively on Envato Market
  • Located in 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.

371 posts
  • Has referred 50+ members
  • Has sold $125,000+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Elite Author: Sold more than $75,000 on Envato Market
+5 more
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
  • Has been part of the Envato Community for over 6 years
  • Has referred 50+ members
  • Has collected 10+ items on Envato Market
  • Sells items exclusively on Envato Market
+2 more
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
  • Has been part of the Envato Community for over 5 years
  • Has collected 1+ items on Envato Market
  • Sells items exclusively on Envato Market
  • Located in United Kingdom
TahaH-Studio says

Thank you guys, I got it working :D

Helpful Information

  • Please read our community guidelines. Self promotion and discussion of piracy is not allowed.
  • Open a support ticket if you would like specific help with your account, deposits or purchases.
  • Item Support by authors is optional and may vary. Please see the Support tab on each item page.

Most of all, enjoy your time here. Thank you for being a valued Envato community member.

Post Reply

Format your entry with some basic HTML. Read the Full Details, or here is a refresher:

<strong></strong> to make things bold
<em></em> to emphasize
<ul><li> or <ol><li> to make lists
<h3> or <h4> to make headings
<pre></pre> for code blocks
<code></code> for a few words of code
<a></a> for links
<img> to paste in an image (it'll need to be hosted somewhere else though)
<blockquote></blockquote> to quote somebody

:grin: :shocked: :cry: Complete List of Smiley Codes

by
by
by
by
by
by