rwmb_the_value()
- This topic has 6 replies, 2 voices, and was last updated 9 years ago by
cardinalacres_old.
-
AuthorPosts
-
April 1, 2016 at 11:38 AM #2637
cardinalacres_old
ParticipantI'm working on a site that will be utilizing The Events Calendar/Event Tickets/WooCommerce for event registration and e-commerce. Meta Box is being used to add some extra meta data to the event "venue" which is a custom post type.
Defining and entering the meta data works fine. When attempting to display the meta data in the front-end I'm running into some odd behavior. When the "venue" itself is displayed, rwmb_the_value() appears to return correct meta data (although for multi-valued fields it returns an array which I wasn't expecting; simple to extra the "value" portion of the array in PHP, though).
However, when "venue" meta data is attempted to be extracted while the event itself is being displayed, I'm getting some weird results. The same PHP code that returns correct extracted "venue" meta data for the venue display no longer works. rwmb_the_value() returns null!
I'm wondering if rwmb_the_value() is expecting some global WP post ID variable to be set. In the situation where I'm having problems, the front-end is displaying an "event" (a custom post with ID 1, say) while displaying additional data about the "venue" (another separate custom post with ID 2, say). So, data is being displayed from TWO custom posts with two different post IDs.
Happy to give more details/clarification if needed...
April 1, 2016 at 1:34 PM #2641Anh Tran
KeymasterHi,
Thanks for asking this. There are 2 internal helper functions
rwmb_get_value()
andrwmb_the_value()
which are used inrwmb_meta()
function. They're not 100% stable since v4.8.0 so I haven't put them in the docs yet.Briefly,
rwmb_get_value
returns the raw value stored in the post meta, whilerwmb_the_value
returns (or outputs) the *meaningful* value in the frontend. Meaningful = option label for select box, post title for post field, a colorful dot for color field, etc.Both functions accept the same parameters as
rwmb_meta
. Parameters also share the same meaning.rwmb_get_value( $field_id, $args = array(), $post_id = null ) rwmb_the_value( $field_id, $args = array(), $post_id = null, $echo = true )
They also use
$post_id
if you want to get meta value from a specific post.In your case if the result goes unexpected, please try setting up the
$post_id
. Anyway, there was also a topic reporting the same problem happened because of wrong post ID. But I couldn't find out whyApril 1, 2016 at 8:16 PM #2647cardinalacres_old
ParticipantI am passing a value for
$post_id
. In one scenario, I get correct results (although, unexpectedly in array format) while in another scenario I do NOT get correct results. Exact same code, exact same passed parameters.This points to something in the
rwmb_the_value()
function not behaving correctly (or something in my hosting environment being corrupted). I have created a separate site (database and WordPress files from scratch) to test whether or not something in my WordPress install is causing this and found the same results.Again, my guess is that
rwmb_the_value()
(or other functions or WordPress APIs that it calls) is relying on some global WordPress value being set. As I attempted to explain previously, in the scenario whererwmb_the_value()
does not work is a scenario where I'm attempting to retrieve meta data for a post which is NOT the one being displayed (i.e., I'm including data and meta data from a separate post in the post that WordPress is displaying in a normal manner).April 4, 2016 at 8:25 AM #2653Anh Tran
KeymasterMaybe you're right. I need to check that again. Can you tell me which field type are you using?
April 4, 2016 at 9:32 AM #2655cardinalacres_old
ParticipantThis is for a radio list. The odd thing is that it works in one situation (albeit, with an array as the return value) and not at all in another with the same theme and plugins.
April 4, 2016 at 10:59 AM #2657Anh Tran
KeymasterJust found the bug and pushed a fix on Github. Can you please test that?
April 4, 2016 at 11:05 AM #2658cardinalacres_old
ParticipantPerfect! Thanks for the quick fix, much appreciated!
-
AuthorPosts
- The topic ‘rwmb_the_value()’ is closed to new replies.