BuddyDev

Search

[Resolved] Adding a gallery automatically on post creation

  • Participant
    Level: Master
    Posts: 413
    Venutius on #12795

    I’ve got a few different files of code so that might get a little complex.

    What I’m thinking is that it’s because I’m effectively creating two psts at once, my own custom post type and your gallery post. It might be as simple as moving when I load the mpp actions file, let me check.

  • Participant
    Level: Master
    Posts: 413
    Venutius on #12796

    No that’s not it but it’s something like that, I think I need to add a check to make sure the custom fields are only being added to the post type of my custom post type, and not yours.

  • Keymaster
    (BuddyDev Team)
    Posts: 24706
    Brajesh Singh on #12800

    Hi George,
    In your code, It seems to me you are using update_post_meta with gallery id.

    You are correct that you should not add custom fields for the post types which were not specific to your own implementation.

    Regards
    Brajesh

  • Participant
    Level: Master
    Posts: 413
    Venutius on #12801
    This reply has been marked as private.
  • Participant
    Level: Master
    Posts: 413
    Venutius on #12802

    I wrapped the update_post_meta commands in a check to make sure the post type was my type but that did not work.

  • Keymaster
    (BuddyDev Team)
    Posts: 24706
    Brajesh Singh on #12805
    This reply has been marked as private.
  • Participant
    Level: Master
    Posts: 413
    Venutius on #12806
    This reply has been marked as private.
  • Keymaster
    (BuddyDev Team)
    Posts: 24706
    Brajesh Singh on #12810

    Hi George,
    Please try changing this line

    
    
     if ( $typenow == 'buslsite' ) {
    
    

    to

    
     if ( get_post_type( $post_id ) == 'buslsite' ) {
    
    

    That should do it.

  • Participant
    Level: Master
    Posts: 413
    Venutius on #12811

    That fixed it Brajesh, thanks for that, is the $typenow variable a bit hit and miss?

    By the way, my new plugin’s been accepted in the WordPress directory, I’m very pleased to see it listed.

  • Keymaster
    (BuddyDev Team)
    Posts: 24706
    Brajesh Singh on #12812

    Congratulations.
    Please do link me when you push the code 🙂

    About the code:-
    $typenow is fine but it tell you more or less about the editing screen and not exactly about the post type being saved.

    In our case, we were saving 2 entries(1 for custom post and another for gallery post type). For both, the $typenow remained same as the second post(gallery) creation was triggered programatically. Using get_post_type( $post_id) gave us the current post being saved’s post type.

    Hope that clarifies.

    Regards
    Brajesh

The topic ‘ [Resolved] Adding a gallery automatically on post creation’ is closed to new replies.

This topic is: resolved