This is a bit tricky to explain, but I desperately need help with this.
I have created 3 plugins for a real estate agent using wordpress custom post types. The 3 plugins are Properties, Communities, and Agents. On the properties plugin, i’ve added a series of custom meta boxes for users to enter extra information about the property. One of these meta boxes is a select drop down that is populated with a list of all communities that have been entered into the communities plugin. In addition, i’m also trying to do the same for agents. The purpose of these select boxes is so that you can attach a community, and an agent to the property, and display them on the front end with a link to their posts respectively.
The first select box I put in worked… sort of. Depending on where the select box was placed in relation to the other custom meta boxes, the custom meta boxes listed after the select box would all lose their value. The value was still stored in the database because it would show up on the front end, but in the backend the value wouldn’t appear. I resolved the issue by moving the Select Neighborhood box to the last option and moved on. Now that i’m trying to do the same with Agents, I have a big issue because one of them has to be added in added before the other, leaving the last field in my list broken.
After racking my brain for hours, I think i’ve narrowed the issue down to the loop that I used to pull a list of custom post types. If I remove the loop from my function, then the field after it begins to work. I haven’t the foggiest idea where i’m going wrong.
I’m getting better with PHP, but honestly i’m somewhere between intermediate and novice… I know enough to figure out how to create these plugins, but i’m far from a developer… The functions get_prop_neigh_dropdown() and get_prop_agent_dropdown() are the issue. Anyways, if anyone could help, here’s my code below:
Any help would be greately appreciated.
Have you tried stashing the global $post variable before firing off any other WP_queries?
$stash = $post; get_dropdown_fn(); // makes a query, loops, and resets $post = $stash;
TCBarret you’re a godsend. At first I had no clue what you were talking about and then I tried adding the $stash = $post and $post = $stash around each of my function calls, and sure enough it worked. I have no idea why to be honest, this is where I think development flies over my head, but none the less thank you TCBarrett, you solved my problem. Both fields are now showing up as they should.
- The topic ‘Issue with custom meta box in my custom post type’ is closed to new replies.