• Resolved christianj40

    (@christianj40)


    Hello,

    I have a custom taxonomy called “company,” which is in a plugin I had developed. The field is in several locations, one being the user’s profile. For example, User A is tied to Company A(one of the options from the custom taxonomy). I have several ACF fields that I have attached to the taxonomy, for example, the companies brand color, logo, and favicon. So my issue is trying to pull the ACF fields from the taxonomy that the user is attached to. For example, if User A is tied to Company A, Company A’s branding (color/logo/favicon) will be pulled.

    Thanks!

    P.S. I am new to PHP, but I have coded this to pull the ACF from the user’s profile. I would really appreciate it if we can edit this code to fit my above issue.

    
    //Pulls Color from users profile
    add_action( "wp_head", "primary_color");
    add_action("admin_head","primary_color");
    function primary_color(){
    $branding = get_field('primary_brand_color',"user_" . get_current_user_id());
    //Fallback color: ABCO green	
    if (empty($branding)) $branding ='#029776';
    echo '<style type="text/css">
    :root{--branding:'.$branding.';}
    </style>';
    }
    
Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Is this primary_brand_color field for sure something stored on the user? Or is it something from term meta?

    Asking because if it’s term meta, then the question I have next is what data is stored on the user, to relate them to the company term. Term ID? Term slug? etc.

    If say term ID, then you would know what term to fetch term meta from, by switching out the "user_" . get_current_user_id() portion with "company_" . $term_id_from_user_meta or similar.

    Really depends on what data is stored where.

    Thread Starter christianj40

    (@christianj40)

    Hello!

    I’m sorry for the late reply! My response was never posted.

    To answer your question, I’m not sure where they are being stored (I know the main wp database, but other than that idk). I do know when I export my users the custom ACF fields are included.

    I tried your suggestion of "company_" . $term_id_from_user_meta and it didn’t work. I also tried replacing “company” with the fields name in devtools “approver_company”.

    I would be more than happy to set up a staging site for you.

    Thanks,
    Christian

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    It’s still primarily a question of which type of data is stored where, and how to best query for that part. It’s not an issue with CPTUI itself as we don’t do anything custom or special around meta data, especially ACF based.

    So…Let’s take an example user and an example company term from your setup, and confirm some details.

    1. Where is the connection between the two being made? When editing the given user? Say a dropdown of available companies? If yes, let’s list out the value saved from a user with a chosen company.
    2. Let’s also grab the set primary color meta value on the term for that company, and list out its value here in the thread.

    I think I can maybe mentally map out code needed based on that.

    Thread Starter christianj40

    (@christianj40)

    Hello!

    1. The connection is being made through the 3rd party plugin I had developed(I believe).

    Plugin breakdown:

    Attaches companies to products(dropdown).
    Attaches companies to users(dropdown).

    Once these above requirements are met, the plugin runs the rest of its programming.

    On the user’s profile, it is being shown as a dropdown with a list of companies (added through the CPT UI page)

    ” let’s list out the value saved from a user with a chosen company” I’m lost on what you mean here. The values that are in the dropdown are the companies that are added through the CPT UI page.

    2. I’m lost on what you mean here as well.

    One company I have is labeled “avo” on the CPT UI page, the primary color value is #e22726.

    Please let me know another way I could help!

    Thanks,
    Christian

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    You have dropdowns, one on the user profile, one on the terms.

    You edit User #1. You choose ACME from the dropdown for its chosen company.

    Hypothetically, the label says “ACME Company”, and the value of the dropdown, stored in the database as user meta is “acme_company” or maybe it’s a numeral ID of “42”. Here’s where I’m asking you to confirm what is actually stored as the user meta value. Is it “acme_company” ? is it “42” ? Is it something else? I’m assuming it’s somehow related to your “company” taxonomy and one of the terms in that list.

    You also have these “company” terms in general, that have various companies set up on them, and they have their own metadata like brand color, brand logo, etc. Correct?

    If I’ve followed everything correctly, you’re trying to display company information for the company associated with that user, somewhere you’re displaying general user content. So you need to fetch your user meta for that chosen company, which I am presently believing is going to be taxonomy term data. Once you have that, you need to do a term meta lookup based on that value, to grab that company/term’s branding color, etc.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Pulling ACF from CPT UI’ is closed to new replies.