Change listing category programmatically

This topic contains 6 replies, has 3 voices, and was last updated by  Kiran 5 years, 10 months ago.

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

Open Support Ticket
  • Author
    Posts
  • #433418

    Alex Howes
    Expired Member
    Post count: 175

    Hello,

    Is there a function that can be used to change the category of a listing programmatically?

    Thanks,
    Alex

    #433458

    Kor
    Moderator
    Post count: 16516

    Hi Alex,

    Thanks for your post. Could you tell us a little bit more about what are you trying to achieve?

    Thanks!

    #433545

    Alex Howes
    Expired Member
    Post count: 175

    Hi Kor,

    I have a form (separate to GD) and when it’s submitted I’d like to change the category of the user’s listing by specifying the listing ID. I’ve created the form and have written a php snippet to hook into the form submit action. I was wondering if you knew what GD function I could use to change the listing category programmatically. I considered using geodir_save_post_meta but the category field looked complicated, so I wasn’t sure.

    Alex

    #433659

    Alex Howes
    Expired Member
    Post count: 175

    I was also wondering if there’s a GD function to check the category of a listing programmatically?

    #433711

    Kiran
    Moderator
    Post count: 7069
    #434728

    Alex Howes
    Expired Member
    Post count: 175

    Hi Kiran,

    Thanks for your reply. I’ve had a look at the code- can I simply use the WP function wp_set_object_terms with $post_category set to an array containing the category ID?

    Alex

    #434788

    Kiran
    Moderator
    Post count: 7069

    Hello Alex,

    Yes, you can assign categories to listing by using that function, but you need to also execute function geodir_set_postcat_structure() (see https://github.com/GeoDirectory/geodirectory/blob/master/geodirectory-functions/post_functions.php#L472 )

    This function will adjust default category and category structure after assigned to listing.

    Kiran

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

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

Open Support Ticket