Support Forum » User Profile

Forum Replies Created

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • Jon WhippleJon Whipple
    Participant

    Oh also, Long,

    Thank you for updating those pages describing using the functions, the examples in Twig as well as PHP help guys like me learn how logic is expressed using different languages and markup schemes. I really appreciate it a lot.

    Jon WhippleJon Whipple
    Participant

    Hi Long,

    OK, thanks, this is working now and outputting expected values.

    Fantastic and thank you.

    So as I understand it, a value in an array is referred to as an 'item'. I suppose if you know the key name you can get that specific item out of the array? I would have to find the syntax to do that.

    I put the {{ mb.rwmb_the_value( 'kind_of_business', '', post.ID, false ) }} function after the loop that was stepping through the array. It returns the value as an HTML list as I understood from the docs on that function.

    For those of you following along this is the code that is working for me. It makes a "client" tile for display on a client listing page. It selects all the post objects that are from my custom post type called Client it sorts them alphabetically and then for each of the clients that has the spotlight field set to true it writes HTML for the entry. You can see output of the loop through the business type using mb.rwmb_meta() function, followed by me using the {{ mb.rwmb_the_value( 'kind_of_business', '', post.ID, false ) }} after.

    {% set args = {post_type: 'client', posts_per_page: -1} %}
    {% set spotlights = mb.get_posts( args )|sort((a, b) => a.post_title <=> b.post_title) %}
    {% for post in spotlights %}
        {% if post.client_spotlight == 1 %}
            <div class="client spotlight">
                <h3>
                    <a href="{{ post.post_url }}">{{ post.post_title }}</a>
                </h3>
                <p>
                    {{ post.post_excerpt }}
                </p>
                <p>
                    {{ post.client_website }}
                </p>
                <p>
                    <b>Spotlight</b>
                </p>
                <p>
                    <b>Kind of business</b>
                    {% set kob = mb.rwmb_meta( 'kind_of_business', '', post.ID ) %}
                    {# now I have an Array named kob#}
                    {% for item in kob %}
                        {{ item }}<br>
                    {% endfor %}
                    {{ mb.rwmb_the_value( 'kind_of_business', '', post.ID, false ) }}
                </p>
                <hr>
            </div>
        {% endif %}
    {% endfor %}

    Here is a screen grab of the incomplete card
    https://share.getcloudapp.com/4gunbG56

    Jon WhippleJon Whipple
    Participant

    Hi Long,

    I am trying to follow along with all of this, but I think I am missing some key things because I am a novice.

    I can get an array from the checkbox field using
    {% set kob = mb.rwmb_meta( 'kind_of_business', '', post.ID ) %}
    This works and if I
    {{ kob }} I see the word Array in the layout.
    This is good.

    The checkbox list docs https://docs.metabox.io/fields/checkbox-list/ give this example in PHP

    $values = rwmb_meta( $field_id );
    foreach ( $values as $value ) {
        echo $value;
    }

    and then add
    rwmb_the_value( $field_id ); to display the field label. I wouldn't know how to use this function in relation to the previous one.

    My best guess at trying to do this in Twig is

    {% set kob = mb.rwmb_meta( 'kind_of_business', '', post.ID ) %}
    
    {# now I have an Array named kob printing kob results in Array being displayed. YAY! #}
    
    {% for item in kob %}
        {% set type = mb.rwmb_the_value( 'kind_of_business' ) %}
        {{ type }}
    {% endfor %}

    Which doesn't work. the rwmb_the_value() function requires the field name but I don't think that field exists within the array?

    Jon WhippleJon Whipple
    Participant

    Thanks, Long. I appreciate your notes and links. Not afraid of PHP and Twig and the like, just a novice and am trying to learn. I will be able to study and try these later today.

    As I understand things at first glance (before really getting into it)

    • I am doing something here that is called a "custom query" that's a term I have seen in a lot of Different WordPress conversations, but I still don't know what it actually means. I wonder what the difference is between a query and a custom query and why it matters? (No need to answer anybody unless you want to)
    • I am using a loop to try and get the value in the checkbox list, it's just the wrong loop. I need to access the data I want using rwmb_meta(), and maybe other Meta Box helper functions
    • I can also use rwmb_the_value() and rwmb_get_field_settings() from my view to get some of the values. I don't yet know how to use these but I will learn.
    • Not sure how to know/determine when I can simply use the MB Views' Insert Field functionality, or when I have to use a rwmb_ helper function. Trial and error I guess (I have read the definitions of these functions but they are just beyond the edge of my limited programming knowledge.

    I'll add notes here about my progress.

    Jon WhippleJon Whipple
    Participant

    I need to display the label or values from the post's Kind of Business field which is a checkbox list.

    Jon WhippleJon Whipple
    Participant

    Also: Meta Box is fantastic. I find that the extensions provide the mechanics and the UI that fills the gaps between my novice developer skills and my technical inclination as a graphic designer. I am learning a lot because MB extensions bridge the gaps in my understanding by demonstrating utility and generating accompanying code that I can study and begin to learn.

    Jon WhippleJon Whipple
    Participant

    I saw the update to Meta Box AIO 1.11.8 (including MB Views 1.3.1), read the notes, and updated immediately. Thank you. The issue I outlined is fixed. I appreciate your prompt attention.

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