Support Forum
I am using MB Views more and more.
Before MB I use WP_Query to loop though posts. Inside the result I did an shortcode / function to display a map based on the subfields. Inside the shortcode I retrieve the title with :
get_the_title() and the route_map with $location = rwmb_get_value( 'route_map' );
Calling the function or shortcode doesn't work: I have to give the postId to the function or shortcode and then change the complete code.
function route_function($id = null) {
$post = get_post( $id );
echo $post->post_title;
etc
Is there another way to do this?
Hi Cees,
Can you please share the full scenario of your case? Where do you add the function route_function
and create the query? Some screenshots would be highly appreciated.
In the View, you can use the custom query to query posts as well https://docs.metabox.io/extensions/mb-views/#custom-query
Hi Long,
Maybe a bad explanation. I try to explain. You know the repeater in Oxygen.
I have a CPT routes. When I do a repeater / wp_query on the CPT that I could load a shortcode [showroute] to do some functionality. That shortcode use the PostId that is queried. So this works:
rwmb_get_value( 'route_map' );
Now I use the MB View to load all the posts in the CPT. Within the loop I do the same shortcode [showroute]. But now there is no PostId so inside the shortcode I have to use rwmb_get_value( 'route_map','',$postid ); The $postid is send in the shortcode like [showroute postid=post.id]
For now I have replaces the shortcode to an function and do something like this:
{{ mb.route_function(post.ID) }}
Hi,
If you use the view to create a query to show posts (CPT) so no need to use the repeater of Oxygen, just add the view shortcode to the builder to show posts. Running a PHP function in view and passing the post ID to it is a good way {{ mb.route_function(post.ID) }}
https://docs.metabox.io/extensions/mb-views/#running-php-functions