WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Get option name by value (6 posts)

  1. Topher
    Member
    Posted 1 year ago #

    I have a custom content type with a meta field holding a value of "Boys Basketball".

    I also have a WordPress option that has a taxonomy id in the name, and "Boys Basketball" in the value.

    How can I get the option name (taxonomy_234 in this case) knowing ONLY the value that I have?

  2. Topher
    Member
    Posted 1 year ago #

    Update: I see how I could get this info with a raw mysql query, I'm wondering if there's a WordPress Way.

  3. esmi
    Forum Moderator
    Posted 1 year ago #

  4. Topher
    Member
    Posted 1 year ago #

    No, that's the opposite of what I need. That gets the value by name. I need the name by value.

  5. Topher
    Member
    Posted 1 year ago #

    If I were to do it in sql it would be:

    SELECT
      option_name
    FROM
      options_table
    WHERE
      option_value LIKE '%program%'
    AND
      option_value LIKE '%Boys Basketball%'
    AND
      option_name LIKE '%taxonomy_%'

    and my row looks like this:

    option_id	option_name	option_value	autoload
    195776	taxonomy_294	a:1:{s:7:"program";s:15:"Boys Basketball";}	yes
  6. Topher
    Member
    Posted 1 year ago #

    I accomplished what I needed with a raw query. I wrote it as a fairly feature complete plugin which I'd be willing to release if anyone were ever interested.

Topic Closed

This topic has been closed to new replies.

About this Topic