Post type ID's (2 posts)

  1. landwire
    Posted 3 years ago #

    Hi there,
    I am using different custom post types (car, bike, scooter), which works great. By standard they all use a shared running ID, so let's say I create:

    car -> ID=1
    car -> ID=2
    Bike -> ID=3
    Scooter -> ID=4
    car -> ID=5
    Bike -> ID=6

    What I would like to achieve is another DB entry (post_type_ID) that logs the unique ID of the post type added. So the top example would become like this:

    car -> ID=1 & post_type_ID=1
    car -> ID=2 & post_type_ID=2
    Bike -> ID=3 & post_type_ID=1
    Scooter -> ID=4 & post_type_ID=1
    car -> ID=5 & post_type_ID=3
    Bike -> ID=6 & post_type_ID=2

    Is there a way to do this with a function? I was thinking of counting the post types in the DB and then increasing that value by 1 and writing it to the DB on each post creation. Unfortunately I am crap at coding...

    Or maybe that is total nonsense? Would it be better to have a column for each post type in the DB. car_ID, bike_ID, scooter_ID. Those values could be in the post_meta table.... Then at least all values are unique. Is there a way to grab the highest number in the DB of a column and increase it by 1? Sorry, rubbish at mySQL too.
    Anyone else done anything like that or could help out?

  2. Peter_L
    Posted 3 years ago #

    Why would you want this? Does this solve a problem you have?
    Just query what you need.

Topic Closed

This topic has been closed to new replies.

About this Topic