0

i tried to make plugin import xml . That works fine except that the post id are duplicated always when am importing new data from xml . Here comes the code snippet:

$ag_post_id = wp_insert_post(array (
    'post_type' => 'houzez_agent',
    'post_title' => $prop->agent->name,
    'post_status' => 'publish',
    'comment_status' => 'closed',   // if you prefer
    'ping_status' => 'closed',      // if you prefer
));

if ($ag_post_id) {
    update_post_meta($ag_post_id, 'fave_agent_email', ''.$prop->agent->email.'');
    update_post_meta($ag_post_id, 'fave_agent_office_num', ''.$prop->agent->phone.'');  
    update_post_meta($ag_post_id, 'fave_agent_office_num', ''.$prop->agent->phone.'');
    update_post_meta($post_id, 'fave_agents', ''.$ag_post_id.'');   
    update_post_meta($post_id, 'fave_agent_display_option', 'agent_info');  
}
}
else
{
    update_post_meta($agentresult[0]->ID, 'fave_agent_email', ''.$prop->agent->email.'');
    update_post_meta($agentresult[0]->ID, 'fave_agent_office_num', ''.$prop->agent->phone.'');
    update_post_meta($post_id, 'fave_agents', ''.$agentresult[0]->ID.'');
    update_post_meta($post_id, 'fave_agent_display_option', 'agent_info');
2
  • I don't understand your question. You're talking about "users are duplicated", but in the posted snippet you are inserting a post. Could you please elaborate? (by editing the question itself, not in a comment please) – kero Jul 3 '18 at 14:55
  • There is no code to check if a 'user' post with the same name exists. Be mindful that if you keep using the word users people will think you're talking about actual users, not posts of type houzez_agent – Tom J Nowell Jul 3 '18 at 15:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.