Forum Replies Created
-
AuthorPosts
-
June 2, 2021 at 3:58 AM in reply to: ✅Cannot access values and labels in a checkbox field loop #28606
Jon Whipple
ParticipantOh 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.
June 2, 2021 at 3:50 AM in reply to: ✅Cannot access values and labels in a checkbox field loop #28605Jon Whipple
ParticipantHi 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
spotlightfield set totrueit writes HTML for the entry. You can see output of the loop through the business type usingmb.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/4gunbG56June 1, 2021 at 12:28 PM in reply to: ✅Cannot access values and labels in a checkbox field loop #28585Jon Whipple
ParticipantHi 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?May 31, 2021 at 10:23 PM in reply to: ✅Cannot access values and labels in a checkbox field loop #28568Jon Whipple
ParticipantThanks, 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()andrwmb_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.
May 31, 2021 at 4:00 AM in reply to: ✅Cannot access values and labels in a checkbox field loop #28541Jon Whipple
ParticipantI need to display the label or values from the post's Kind of Business field which is a checkbox list.
May 20, 2020 at 1:20 AM in reply to: ✅UI doesn't match behaviour described in documentation for MB Views #19690Jon Whipple
ParticipantAlso: 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.
May 20, 2020 at 12:49 AM in reply to: ✅UI doesn't match behaviour described in documentation for MB Views #19689Jon Whipple
ParticipantI 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.
-
AuthorPosts