Tagged: php shortcode custom field
December 21, 2020 at 5:23 am #24462
Dear WP team,
In short: How to create a php snippet to display a WPSP list filtered with additional custom fields?
I’m using a shortcode to present a WPSP list but would ask for your help so it can be defined correctly via php instead. I’ve made a few attempts, without success.
The shortcode includes several additional parameters, related to a custom field created with the ACF plugin to rank & order the posts. Since i need to filter and order the output in a specific way, i adjusted the shortcode as suggested by Tom here.
The end result:
[wp_show_posts id="1477" settings="meta_key=network-order&orderby=meta_value_num&order=ASC"]
– where “1477 is my list’s Id and “network-order” is the custom-field’s name
This works well but leads to a known problem: every time the page is edited anew, the “&” is replaced by “&”, breaking the functionality unless it’s manually cleaned. This has been (raised in another post, but the php equivalent was not indicated.
Since this is for a client, the manual editing step might fail and i would prefer to implement a php snippet to go in the functions.php of the child theme (based on Generate Press Pro, if relevant). The shortcode goes inside a container block (Generate Blocks, if relevant – i think you can spot a trend in user preferences here ;))
If doable, how should the php snippet look like?
Thank you in advance for your assistance!
PauloDecember 21, 2020 at 5:32 am #24464
The example above was cleaned, funnily enough 🙂
Just for clarity: The “&” is replaced by
&(“&” followed by the ampersand HTML code). This leads to the problem described above. I understand this is not WPSP’s flaw, rather WordPress’ beahviour.
Best regards.December 21, 2020 at 4:28 pm #24479elvinModerator
You can try wrapping the WPSP shortcode within another shortcode as Tom suggested here:
His reply includes a snippet for making shortcodes incase you need it.December 23, 2020 at 6:56 am #24528
Thanks for the link. That was all i needed and it worked perfectly!
Great support, as always.
Wish you all a good holiday season and start of 2021!
PauloDecember 27, 2020 at 6:54 pm #24655elvinModerator
Nice one! Glad you found it useful. No problem. 🙂
Stay safe. 😀
- You must be logged in to reply to this topic.