Programmatically add Category to Place

This topic contains 8 replies, has 3 voices, and was last updated by  webresource 8 years, 6 months ago.

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket
  • Author
    Posts
  • #59218

    webresource
    Expired Member
    Post count: 19

    Hi guys,

    I need to programmatically add a category to a place.
    I thought it was as easy as setting the default_category and geodir_iot_device_name in wp_geodir_gd_place_detail an adding an entry in wp_term_relationships.

    What else am I missing?

    Thanks,
    Helga

    #59234

    Paolo
    Site Admin
    Post count: 31206

    Hi,

    did you also add the ID to gd_placecategory? If you are adding it as default category, you may have to also add marker_json details.

    Let us know,

    #59239

    Stiofan O’Connor
    Site Admin
    Post count: 22956

    Hi Helga,

    Are you trying to edit the DB direct? (you would need to change a few fields) If you let me know what you are trying to achieve i will let you know the best solution.

    Thanks,

    Stiofan

    #59399

    webresource
    Expired Member
    Post count: 19

    I did add the ID to gd_placecategory too and i also added marker_json detail.
    (And the markers are working fine, too! 🙂 ) However, when I go to the backend to edit the place, I see that the category-dropdown says “Select Category”.

    Basically what I’m trying to do is: Check an external data source on init, and if there’s new place info in it, then create new places as given by the external source. That works totally fine by now, except that I haven’t figured out how to set the category properly.

    #59567

    webresource
    Expired Member
    Post count: 19

    > Are you trying to edit the DB direct? (you would need to change a few fields)

    Which fields would that be?

    #59573

    Stiofan O’Connor
    Site Admin
    Post count: 22956

    Hi,

    i am not sure how you are doing this but yu might want to check the two functions in geodirectry-functions/post-functions.php (they are documente in the source

    geodir_set_postcat_structure() and geodir_save_listing() (if using the seond one you dont need to sue the first)

    https://wpgeodirectory.com/docs/codex/geodirectory_functions/geodir_set_postcat_structure/

    Let me know if you have any questions.

    Thanks,

    Stiofan

    #59649

    webresource
    Expired Member
    Post count: 19

    Hi,

    I tried the following:
    geodir_set_postcat_structure($post_id, ‘gd_placecategory’, 26, array(26));
    No effect, though. I also double-checked the names and figures.

    Can you simply tell me the database fields that I need to update?

    Thank you.
    Helga

    #59683

    Stiofan O’Connor
    Site Admin
    Post count: 22956

    Hi Helga,

    OK the last part follows a bit of a strange array structure, i will show some examples below

    
    
    Array
    (
        [gd_placecategory] => 9,y:#8,y:#14,y:#10,y,d:
    )
    
    
    Array
    (
        [gd_placecategory] => 9,y,d:#8,y:#10,y:#14,y:
    )
    
    
    Array
    (
        [gd_placecategory] => 9,y,d:
    )

    basically they are split on the “:” the “,d” sets the default and anythig after the first requires a # at the start.

    Doing it this will will save a lot of other calls to get category icons etc.

    Thanks,

    Stiofan

    #59773

    webresource
    Expired Member
    Post count: 19

    Thanks, that did the trick 🙂

Viewing 9 posts - 1 through 9 (of 9 total)

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket