Problem:
I want pass post-fields to own php-function and then display the output in Views loop editor.
What I'm trying to get is function that parses output from 2 different custom fields containing date-time (2017-09-21 11:00:00). I can compare and format them easily in php-function, but not in Views Loop.
How do I pass those two fields to my own php-function and display result in loop?
Solution:
1. How do I pass those two fields to my own php-function and display result in loop?
==> You can make shortcode for your php function and pass those fields in shortcode attributes, like:
[my_custom_shortcode attr_1="field1_shortcode" attr_2="field2_shortcode"]
- Then after processing those fields you can return result back to the shortcode for display..
- Here is WP shortcode API: https://codex.wordpress.org/Shortcode_API
2. Client used following php-code into theme’s functions.php file:
function this_is_test_shortcode_func( $atts ) { $attlist = shortcode_atts( array( 'first' => '(no first)', 'second' => '(no second)', ), $atts, 'this_is_test_shortcode' ); return "Output 1: " . $attlist['first'] . " / 2: " . $attlist['second']; } add_shortcode( 'this_is_test_shortcode' , 'this_is_test_shortcode_func' );
-- And used shortcode in Loop Output Editor like this:
[this_is_test_shortcode first="[wpv-post-title]" second="[wpv-post-date]"]
It outputs nicely those two fields as a return.
Relevant Documentation:
- https://toolset.com/documentation/user-guides/conditional-html-output-in-views/using-custom-functions-in-conditions/
Everyone can read this forum, but only Toolset clients and people who registered for Types community support can post in it.
Sun | Mon | Tue | Wed | Thu | Fri | Sat |
---|---|---|---|---|---|---|
- | 12:00 – 17:00 | 12:00 – 17:00 | 12:00 – 17:00 | 12:00 – 17:00 | 12:00 – 17:00 | - |
- | 18:00 – 21:00 | 18:00 – 21:00 | 18:00 – 21:00 | 18:00 – 21:00 | 18:00 – 21:00 | - |
Supporter timezone: Asia/Karachi (GMT+05:00)
This topic contains 2 replies, has 2 voices.
Last updated by jussiP 6 years, 7 months ago.
Assisted by: Noman.
The forum ‘Types Community Support’ is closed to new topics and replies.