My situation is as followed. I created a custom post type, which is called backgrounds. Each background has a designer-name and of course featured image. That works like a charm. The thingy I wanna do now is to make it possible to set a background post, as the current background. But is there any possibility to check if any other background is set to that? I mean I will create a custom field, a checkbox where it says, set as current background. When I post it, it will check which other background has it true, set it to false. Like a unique value, which only exists for one post only.
Hope you guys understand me. Having some trouble with my English right now.
Came up with an idea. is it possible to implement a function before the publish-post action? If so, is it possible to create a query to check which post has the "as background" as true?
But my problem is, that get_post_meta wont work immediately, it seems that calls the database entry too early... Like before it's posted into database... Cause when I update the post 2 times, the correct value is inside, otherwise the value I had before is in there... Anyone know how to get that work properly?
Got a new version ,but I cannot get the update_post_meta work properly... After setting it to current background, I want the checkbox beeing unchecked again.
Here is my code:
function set_background( $post_ID ) { global $posts, $post;
I'm having trouble with wordpress.
My situation is as followed. I created a custom post type, which is called backgrounds. Each background has a designer-name and of course featured image. That works like a charm.
The thingy I wanna do now is to make it possible to set a background post, as the current background. But is there any possibility to check if any other background is set to that? I mean I will create a custom field, a checkbox where it says, set as current background. When I post it, it will check which other background has it true, set it to false. Like a unique value, which only exists for one post only.
Hope you guys understand me. Having some trouble with my English right now.
But my problem is, that get_post_meta wont work immediately, it seems that calls the database entry too early... Like before it's posted into database... Cause when I update the post 2 times, the correct value is inside, otherwise the value I had before is in there...
Anyone know how to get that work properly?
Here is my code: