After Import Action

Home Forums TurboCSV Support After Import Action

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #11073
    yellowhousedesign
    Participant

    Hey Chris,
    Is there an action that we can hook into after the initial import is done, but before Turbo CSV is done with its mojo? A new project has a requirement to delete any/all posts that are not part of the import after reach Turbo CSV import. So – it’d be a matter of checking for a specific post type and if a post ID that is part of the import  is not part of the existing post IDs, then remove it. So – the action and what holds a list of imported IDs would be awesome. Really appreciate it. Thanks!

    #11074
    Chris
    Keymaster

    Hi,

    From what you said, it sounds like maybe it would be easier to just delete all posts before the import?

    If that won’t work though: ll the normal WordPress actions are called.  The ‘save_post’ action is triggered after each post is created.

    There’s also MapPress action that is called during the import:
    do_action(‘mappress_update_meta’, $post_id);

    Hopefully those actions will be helpful.  If you need to access the import, you can get a list of imports like this:

    $imports = TI_Import::get_list();

    Get one import where $id is the import ID you want to retrieve:

    $import = TI_Import::get_list();

    Get import lines for the import – this returns an array of class TI_Import_Line

    $lines = $Import->get_imported_posts();

    You can take a look at the TI_Import_Line definition to see the fields.  For example:

    $lines[0]->post_id
    #11077
    yellowhousedesign
    Participant

    Hey Chris,
    Appreciate the response. The data will actually be used throughout the rest of the system, so deleting all of them before-hand probably won’t be a good idea. I think that ‘mappress_update_meta’ action may be where I want to do the check.

    It sounds like I could use that action to:

    Grab all of the imported posts with: $lines = $Import->get_imported_posts();
    Then grab all of the posts that current exist (using get_posts())
    Compare the IDs in each and then use http://codex.wordpress.org/Function_Reference/wp_delete_post to remove the ones that don’t match

    Does the TI_Import class also hold the template name in the event I don’t want to do this for every “type” of import? Thanks again!

    #11078
    Chris
    Keymaster

    Hi,

    The TI_Import object has a ‘template’ property that contains a TI_Template object.  You can see both in ‘ti_import.php’.

    #11079
    yellowhousedesign
    Participant

    Awesome – I’ll see what I can do with this. Thanks again!

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.