Home › Forums › Pro Support › PHP version of shortcodes with multiple parameters
Tagged: php shortcode custom field
- This topic has 4 replies, 2 voices, and was last updated 2 years, 9 months ago by
elvin.
-
AuthorPosts
-
December 21, 2020 at 5:23 am #24462
P
ParticipantDear 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 nameThis 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!
Best,
PauloDecember 21, 2020 at 5:32 am #24464P
ParticipantThe 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 #24479elvin
ModeratorHi,
You can try wrapping the WPSP shortcode within another shortcode as Tom suggested here:
https://wpshowposts.com/support/topic/how-to-fix-wpshowpost-tag-element-flashing/#post-22406
His reply includes a snippet for making shortcodes incase you need it.
December 23, 2020 at 6:56 am #24528P
ParticipantHi Elvin,
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!
Cheers,
PauloDecember 27, 2020 at 6:54 pm #24655elvin
ModeratorNice one! Glad you found it useful. No problem. 🙂
Stay safe. 😀
-
AuthorPosts
- You must be logged in to reply to this topic.