• Resolved leanneoleary

    (@leanneoleary)


    Hi,
    I set up a custom post type a few weeks ago and have entered lots of information against this. Today I have been coding my application and have used the below to get data from my post type and to update my post type. This all seemed to have worked really well, but after going back to my WP control panel I have noticed the icon for the custom post type was missing and so went to the CPT UI under Manage Custom Post Types and it states, “No additional post types found”

    //get current stock and update with new stock
    $stock = get_post_meta( $posttype->plant_id, ‘stock’, true );
    update_post_meta($plant->plant_id, ‘stock’, $stock-$posttype->no_of_shelves); `

    Does anyone know what could have happened to this and how I can get it back?

    https://www.ads-software.com/plugins/custom-post-type-ui/

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    both of those functions should have zero effect on the registered post types, unless they are somehow managing to delete the option values saved for our settings, which would be impressive and scary all at once.

    I am curious how you’re getting “plant_id” for your $posttype property, as it would just be $posttype->ID, if in the loop, unless you’re completely constructing your own objects as well.

    Unless it was also somehow deleted, the posts for the post type, including meta data should all still be in the database, it’d just need to have the post type re-registered so that the WP Admin UI knows what to display.

    Hope that gives some sort of ideas for this.

    Thread Starter leanneoleary

    (@leanneoleary)

    $posttype->plant_id is a foreign key not the unique ID for that table. I have looked and it seems there are still entries in the database. You are right its very unlikely this bit of code had anything to do with it. Just a coincidence probably.

    So what is the best way to re-register the post type without having to add everything again?

    many thanks for your help.

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    It’s going to be quickest to just re-set the appropriate settings in CPTUI for the post type in question. Biggest thing will be making sure you match up the used post type slug so that it queries the content properly from that in the posts table. The rest of the settings are pretty straightforward. There’s going to be no magic way unless you still have the saved option in the options table and the plugin’s somehow not picking up the right value out of it.

    Thread Starter leanneoleary

    (@leanneoleary)

    Ok I have gone to CPT UI but cannot find where to reset the settings. Can you point me in the right direction? I have no idea how to match up the post type slugs either :/

    Thread Starter leanneoleary

    (@leanneoleary)

    Ok I have gone to CPT UI but cannot find where to reset the settings. Can you point me in the right direction? I have no idea how to match up the post type slugs either :/

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Just to clarify, I said “re-set” as in set again, not “reset” as in clear everything to a blank state. So if the post type in question is no longer listed in the manage page, you will need to recreate the post type the best you can based on the previous settings that it had.

    Thread Starter leanneoleary

    (@leanneoleary)

    Sorry for being a pain but I still dont have this resolved. I am new to using wordpress and I am not familiar with how post types and posts are entered into the database hence the reason for using a plugin instead of doing this manually.

    I have re-added the post type as you said, so now it is listed in the admin menu. How do I re-link it to all the entries I have in the database so that they are listed in the admin panel and can be edited etc? I also had also set custom fields (using a plugin) so would need to link these back up somehow.

    Many Thanks

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Assuming you matched the post type slug with what you previously had, the rest of it should have fallen in line and you wouldn’t need to re-link anything. The data is likely not lost by any means, thus the associations are all still correct at that level.

    What was the slug you used before, and what is the slug you’re using now?

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘CPT disappeared after using get_post_meta() and update_post_meta()’ is closed to new replies.