Support Forum
Support › Meta Box AIO › Post Content Empty
Hi,
I have set up this query on a CPT template in Oxygen Builder:
<?php
$group_values = rwmb_meta( 'group_m2qbw9n986h' );
if ( ! empty( $group_values ) ) {
foreach ( $group_values as $group_value ) {
$value = isset( $group_value['post_ecian25xrc9'] ) ? $group_value['post_ecian25xrc9'] : '';
$accomm_posts = get_post($value);
print_r($accomm_posts);
echo '<br><br>';
}
}
?>
And it outputs the expected posts but the content of the posts is empty:
WP_Post Object ( [ID] => 15 [post_author] => 1 [post_date] => 2022-05-18 16:43:03 [post_date_gmt] => 2022-05-18 15:43:03 [post_content] => [post_title] => Yurt 1 [post_excerpt] => [post_status] => publish [comment_status] => closed [ping_status] => closed [post_password] => [post_name] => yurt-1 [to_ping] => [pinged] => [post_modified] => 2022-06-06 12:30:28 [post_modified_gmt] => 2022-06-06 11:30:28 [post_content_filtered] => [post_parent] => 0 [guid] => http://localhost/metabox-learn/?post_type=accommodation-type&p=15 [menu_order] => 0 [post_type] => accommodation-type [post_mime_type] => [comment_count] => 0 [filter] => raw )
WP_Post Object ( [ID] => 16 [post_author] => 1 [post_date] => 2022-05-18 16:43:10 [post_date_gmt] => 2022-05-18 15:43:10 [post_content] => [post_title] => Yurt 2 [post_excerpt] => [post_status] => publish [comment_status] => closed [ping_status] => closed [post_password] => [post_name] => yurt-2 [to_ping] => [pinged] => [post_modified] => 2022-06-06 12:29:46 [post_modified_gmt] => 2022-06-06 11:29:46 [post_content_filtered] => [post_parent] => 0 [guid] => http://localhost/metabox-learn/?post_type=accommodation-type&p=16 [menu_order] => 0 [post_type] => accommodation-type [post_mime_type] => [comment_count] => 0 [filter] => raw )
WP_Post Object ( [ID] => 14 [post_author] => 1 [post_date] => 2022-05-18 16:42:55 [post_date_gmt] => 2022-05-18 15:42:55 [post_content] => [post_title] => RWAV [post_excerpt] => [post_status] => publish [comment_status] => closed [ping_status] => closed [post_password] => [post_name] => rwav [to_ping] => [pinged] => [post_modified] => 2022-06-06 12:31:06 [post_modified_gmt] => 2022-06-06 11:31:06 [post_content_filtered] => [post_parent] => 0 [guid] => http://localhost/metabox-learn/?post_type=accommodation-type&p=14 [menu_order] => 0 [post_type] => accommodation-type [post_mime_type] => [comment_count] => 0 [filter] => raw )
Here is the field group for the outputted posts:
<?php
add_filter( 'rwmb_meta_boxes', 'test_accomType' );
function test_accomType( $meta_boxes ) {
$prefix = '';
$meta_boxes[] = [
'title' => __( 'Accommodation Type', 'your-text-domain' ),
'id' => 'accommodation-type',
'post_types' => ['accommodation-type'],
'fields' => [
[
'name' => __( 'Unit Name', 'your-text-domain' ),
'id' => $prefix . 'unit_name',
'type' => 'text',
],
[
'name' => __( 'Unit Description', 'your-text-domain' ),
'id' => $prefix . 'unit_description',
'type' => 'textarea',
'required' => true,
],
[
'name' => __( 'Main image', 'your-text-domain' ),
'id' => $prefix . 'main_image',
'type' => 'single_image',
'required' => true,
],
[
'name' => __( 'Gallery', 'your-text-domain' ),
'id' => $prefix . 'gallery',
'type' => 'image_advanced',
'required' => true,
'clone' => true,
'sort_clone' => true,
],
],
];
return $meta_boxes;
}
How do I include the content in the query?
Thanks
Hi,
Just wondering if you have any help for me on this? For some reason I can retrieve the posts but the content isn't available. I have set up a single template for the Accommodation Type to test that I can access the content, and I can, but for some reason I cannot using the query.
Thanks
Don't worry, after two days of investigation I figured it out myself!
Not sure why you haven't got back to me with some support on this matter - and not sure why I paid for your premium licence when a lot of the time I need to understand PHP and wordpress queries to get the full value from your plugins, and your support is very much lacking.
By the time I've learned everything that I need to know to use your plugins, I'll have enough knowledge to no longer need them
Hi,
Sorry for the late reply.
I see you've created another topic with the same question about the subfield value so I think it should be done on that topic https://support.metabox.io/topic/how-to-query-a-post-field-in-a-group/
To get the full powerful features of Meta Box, you should also have a basic knowledge of WordPress and PHP coding.
Can you please let me know what's wrong with your posts?
Hi Long,
If I had known what knowledge was required to use your product before I purchased I would not have purchased.
As I said, there is no longer an issue as I have spent 2 days learning WordPress and PHP to figure out what to do.
I would have appreciated a reply sooner with some guidance (not just a link to your documentation which I'd already explored for some time before posting here).
Anyhow it's done, onwards and upwards
FYI and for anyone who has a similar issue and finds this post, this is the code that allowed me to query posts in a post field in a cloneable field group. It's probably not the most efficient way of doing it but it works
<?php
// Get values of custom field group
$group_values = rwmb_meta( 'group_m2qbw9n986h' );//Group ID
// Query posts in custom field type posts, in field group
$group_values = $group_values ?? [];
foreach ($group_values as $group_value){
$my_post_id = $group_value['post_ecian25xrc9'];//ID of CPT being queried
$args = array(
'p' => $my_post_id,
'post_type' => 'any'
);
$my_query = new WP_Query($args);
// Get post data and output post title and image for each to test
while ( $my_query->have_posts() ) {
$my_query->the_post();
$post_meta = get_post_meta(get_the_ID(), 'main_image', 'true');
$main_img = wp_get_attachment_image_src($post_meta);
echo '<li>' . get_the_title() . '</li>';
echo '<img src="' . $main_img['0'] . ' "/>';
};
}
wp_reset_postdata();
?>
Hi,
Thanks for sharing your solution. But I do not see it relates to the main issue, post content is empty.
Hi Long,
So one thing I learned along the way was where the post data is stored - I expected it to be in post content (because its the content of the post), but it is stored elsewhere. I'm not sure why the content that I was looking for doesn't show up when I do print_r, but I couldn't see it and I could see that the post content was empty. Anyhow, after much trial and error and investigation I figured out how to query the post and the data that I was looking for.
If you think this forum post is going to not help others then feel free to edit it as you see fit.
Cheers
Hi,
I think the content is empty because you are using a builder plugin that will store the content in a post meta like a field value so the query will return the empty content. You can try to deactivate all plugins except Meta Box, MB extensions then add the content to the post and check the query again.