Skip Navigation

[Resolved] Trying to insert a new post into my custom type post

This support ticket is created 6 years, 3 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 9 replies, has 2 voices.

Last updated by sahrf 6 years, 2 months ago.

Assisted by: Shane.

Author
Posts
#607986

Tell us what you are trying to do?
I am trying to insert a new post manually using code into my custom type post call quote. I have created the relevant post fields. here is my code:
global $wpdb;
$todayquote = date("F j, Y, g:i a");
$my_post = array(
'post_title' => $mydisplayname,
'post_content' => 'Quotes.',
'post_status' => 'publish',
'comment-status' => 'closed',
'ping-status' => 'closed',
'post_author' => 1,
'post-type' => 'quote',
);

$new_post_id = wp_insert_post( $my_post, $wp_error=true );
update_post_meta($new_post_id,'wpcf-eventdates' , $eventDate);
update_post_meta($new_post_id,$new_post_id,'wpcf-nailtechnician', $name);
update_post_meta($new_post_id,'wpcf-wpcf-wigs',$Wigs);
update_post_meta($new_post_id,'wpcf-weaveandextension' ,$WeaveandExtension);
update_post_meta($new_post_id,'wpcf-postcodequote', $postcode);
update_post_meta($new_post_id,'wpcf-starttime', $startAndfinishS);
update_post_meta($new_post_id,'wpcf-finishtime', $startAndfinishF);
update_post_meta($new_post_id,'wpcf-lashestechnician' , $Lashestechnician);
update_post_meta($new_post_id,'wpcf-professionalmakeup', $ProfessionalMakeup);
update_post_meta($new_post_id,'wpcf-braidingandplating', $BraidingandPlating);
update_post_meta($new_post_id,'wpcf-timeavailability' , $timeavailability);
update_post_meta($new_post_id,'wpcf-homevisit' , $homevisit);

if(!is_wp_error($new_post_id)){
echo ' Inserted into database';
}else{
echo $ids->get_error_message();
}
I don't get error and it says the data has been inserted but when i check in the back end I don't see the new post.

Steps
1. go to my site hidden link
2. Add expert to the shortlist
3. Hover on the shortlist icon on the top right of the site which will have 1 item added
4. Click on view my shortlist which take you to the shortlist page
5. Fill in the form and click submit.

Is there any documentation that you are following?

Is there a similar example that we can see?

What is the link to your site?

#608047

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hello,

Thank you for contacting our support forum.

I'm not able to see the me Add expert to the shortlist page.

Could you provide a link to this page ?

Also could you provide me with the credentials to the website so that I can have a look at this for you ?

The private fields will be enabled for your next response.
Thanks,
Shane

#608083

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hello,

Could you send me a link to this page.
2. Add expert to the shortlist

Thanks,
Shane

#608087

Steps
1. login with credential
2. go to the home page of my site hidden link
3. Click Add expert preferable SAHR FODAY to the shortlist
4. Hover on the shortlist icon on the top right of the site which will have 1 item added
5. Click on view my shortlist which take you to the shortlist page
6. Fill in the form and click submit.

#608100

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hello,

I was able to see the issue now but I believe this is because of the code. I'm not seeing a context to the code.

Meaning how is this code going to run ?

Where is this code located.

Also wouldn't it be easier to use our CRED forms for this ? By adding the form to request a quote directly to the profile of the person ?

Because when you view the information on the request page nothing is really there. So I would recommend using CRED to do this.

Thanks,
Shane

#608108

You can find the code in page-shortlist.php line 155. I was thinking of using the CRED form but It would be to complicated to work with the rest of the code.

If you login and go the appearance -> editor - >page-shortlist.

#608116

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hello,

So the reason why the form isn't working as intended is because the POST request is not firing the code to create the post.

I'm not sure how this will be difficult to do with CRED as cred will just be the form interface to create the quote.

Could you let me know what the quote form is for ?

I don't believe this needs to be hardcoded. Maybe allowing me to understand the setup will make see how best to work with this with you.

Looking forward to hearing from you soon.
Thanks,
Shane

#608119

The shortlist page shows what the client have chosen. After filling the form it is then email out to all the chosen expert and I want to also store the data from the filled form into my site. Everything works apart from storing the data in the quote post type.

#608719

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Sahr,

I see what you are trying to achieve, however the issue is the code not working and not that its not creating the Post.

The code more than likely isn't getting called into action.

What I recommend that you do from here is to contact one of our certified consultants for more assistance with this as they should be able to provide a fully coded solution for you .

You can contact them by going to the link below.
https://toolset.com/contractors/

Thanks,
Shane

#608731

I found a different way to do it

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.