WordPress.org

Ready to get started?Download WordPress

Forums

Deleting category from within loop? (1 post)

  1. epicdiyom
    Member
    Posted 2 years ago #

    I'm looking for a way to modify the category of an entry from within the loop, if a particular conditional statement holds true. Basically, code sort of like this inside the loop:

    foreach((get_the_category()) as $checkcat) { if ($checkcat->cat_name == 'Subscribers') { $catmarker = 1; } }
    if ($x = $conditioniwant && $catmarker = 1) { MySQL command to delete Subscribers category from this entry ]

    So far, I haven't found any example of such database modification being undertaken within the loop itself, but it seems like it should be possible with the right MySQL query.

    The problem is that the current WordPress database structure is a little complicated, and although I've read up on the relationship between wp_posts, wp_term_relationships, wp_term_taxonomy, and wp_terms, I'm not sure how to start structuring such a query.

    So, first, can anybody tell me whether I'm barking up the wrong tree in the first place? Does WordPress perhaps lock the database from modification from within the loop? If not, how exactly would I construct a query to modify the category?

    Would it only require deleting a field from the wp_term_taxonomy table?

    Thanks!

Topic Closed

This topic has been closed to new replies.

About this Topic