Thread Starter
Jeshua
(@jeshuavs1)
I’ve created an initial function and shortcode to only show the value of the “value” field of the “currency” cpt and then use it in the page builder or any place:
function fields_multiply() {
$currency = pods( 'currency' );
$value = $currency->display('value');
echo $value;
}
add_shortcode( 'fields_total', 'fields_multiply' );
This is only for test purposes, but didn’t work. The rest is create de variables to create another that shows the result of the multiplication of the “actualrate” field from the “rate” cpt of a certain post of that cpt and “value” field of the “currency” cpt (this is for individual posts that will be created for that cpt).
The code is inside a custom pods-starter plugin that I found googling. The shortcode woks becuase if I change i.e.: echo 'ANYTHING HERE'; rather than the code above inside the function, the echo shows that result anywhere I want with the shortcode “fields_total”.
-
This reply was modified 6 years, 10 months ago by
Jeshua.
-
This reply was modified 6 years, 10 months ago by
Jeshua.
-
This reply was modified 6 years, 10 months ago by
Jeshua.
You aren’t passing a post id in that function, so you’ve only opened the object. There is no ‘connection’ to your existing post at that point.
Check out our Pods object documentation:
https://pods.io/docs/code/pods/
You need to at least pass get_the_id() or $post->ID into your pods('currency') object opening. Check the parameters in the documentation above and the examples on that page.
Thread Starter
Jeshua
(@jeshuavs1)
Thanks!! It works, I was missing the dynamic id to call the custom field for the individual posts of the cpt.
My final function was this:
function fields_multiply () { //START FUNCTION
//GET THE MANUAL RATE
$rate = pods( 'rate', 'manualrate')->find( $params );
$therate = $rate->field( 'therate' );
//FIND CURRENCIES
$currency = pods( 'currency', get_the_id() /* THIS IS WHAT I WAS MISSING */ );
$price = $currency->field( 'price' );
//MULTIPLY AND RESULT
$totalprice = $therate * $price;
echo '<p>' . $totalprice . '</p>';
} //END FUNCTION
// CREATE SHORTCODE
add_shortcode( 'fields_total', 'fields_multiply' );
If I was missing something more, please, I’ll be grateful if you tell me.
-
This reply was modified 6 years, 10 months ago by
Jeshua.
-
This reply was modified 6 years, 10 months ago by
Jeshua.
-
This reply was modified 6 years, 10 months ago by
Jeshua.
-
This reply was modified 6 years, 10 months ago by
Jeshua.
Awesome, nice work 😉 And nope, the code looks great.