Skip to content
Read For Learn
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP

Plugin Shortcode value in post

shortcode_parse_atts

Accepts a string of shortcode attributes and returns an associative array of key/value pairs.

// UNABLE TO TEST THIS
// $value = get_post_meta(get_the_ID(), 'some_value', true);
// $sc = $value [ 'item_ticket_tailor' ][ 0 ];

// TEST DATA - assuming the data is a string
$sc="[custom_event id="3106" ][custom_ticket id="3220" show_price="true"]";

// pad some elements for a better parse
$sc = str_replace("[", " [ ", $sc);
$sc = str_replace("]", " ] ", $sc);

// convert the string shortcode to an array
$array = shortcode_parse_atts($sc);

// the last id is the winner, so custom_event id won't show here
// only custom_ticket id
echo $array[ 'id' ]; // 3220

ALTERNATE

$sc="[custom_event id="3106" ][custom_ticket id="3220" show_price="true"]";

// split up the shortcodes
$sc = str_replace("]", " ", $sc);
$sc = str_replace("[", "[", $sc);
$shorts = array_filter(explode('[', $sc));

$custom_event_id = false;

// loop through each one
foreach($shorts as $short) {

    // get the individual attributes of the shortcode
    $atts = shortcode_parse_atts($short);

    // if the first item in the parsed array is `custom_ticket` then get the id
    if($atts[ 0 ] === 'custom_ticket') {
        $custom_event_id = $atts [ 'id' ];
        break;
    }
}

echo $custom_event_id; // 3220

Related Posts:

  1. shortcode to create dynamic dropdown box form shortcode attributes
  2. do_shortcode based on _thumbnail_id
  3. Meta tags in shortcode
  4. Display post metadata: “title, category, author, date” with shortcode
  5. Shortcodes and a list of IDs?
  6. Run a check for multiple meta key values
  7. Shortcode to show current post category with link
  8. Using shortcode to display array in array
  9. IF Custom field value equals ZERO
  10. Print specific values stored in a post meta array
  11. How to get_post_meta in a shortcode in excerpt on archive pages
  12. Render shortcodes with get_post_custom
  13. Pass a comma separated shortcode attribute to a function
  14. Iteratively add sub shortcodes to php array
  15. How to utilise multiple values from a single shortcode attribute?
  16. How to use multiple (or array) values in $content of shortcode?
  17. return an array with a shortcode
  18. update_metadata() appends shortcode data for every page refresh
  19. Multiple meta key and value search in the query
  20. Str_replace using shortcode with multiple changes
  21. shortcodes inside shortcode to sum values
  22. Display post_meta in Shortcode
  23. Applying if (get_post_meta) to new shortcode
  24. add a meta value to the shortcode twice
  25. convert it into short code & explan how? [closed]
  26. Enqueue Scripts / Styles when shortcode is present
  27. How to only display posts whose meta_value field is not empty?
  28. Conditionally Loading JavaScript/CSS for Shortcodes
  29. What does extract( shortcode_atts( array( do?
  30. How to extract data from a post meta serialized array?
  31. How do I escape a ‘]’ in a short code?
  32. Pass boolean value in shortcode
  33. Show shortcode without executing it
  34. Shortcode always displaying at the top of the page
  35. Redirect function inside a Shortcode
  36. How to create a shortcode with 1 parameter (atts)
  37. how to show the syntax of a shortcode
  38. Custom shortcode being executed when saving page in wp-admin
  39. Change appearance of shortcode text inside editor
  40. current_shortcode() – detect currently used shortcode
  41. shortcodes output before content [duplicate]
  42. WordPress plugin shortcode not working
  43. How to add stylesheets only to pages with specific shortcode?
  44. Using get_option() in JavaScript
  45. Shortcode empty attribute
  46. How does a shortcode work?
  47. Shortcode outputs at the top of the_content
  48. the_excerpt and shortcodes
  49. Using wp_editor in shortcode
  50. Remove wpautop from shortcode content / remove whitespace in buffering
  51. Get current post id witout passing in shortcode
  52. Why are you using add_action for shortcode?
  53. How to get URL param to shortcode?
  54. How to add multiple buttons to TinyMCE?
  55. Check if post/page has gallery?
  56. Get first video from the post (both embed and video shortcodes)
  57. Get shortcode name from within it’s callback function? [duplicate]
  58. Wordspress add into my javascripts
  59. Making a Shortcode [NEXT] and [PREVIOUS] to place into specific posts for post navigation
  60. How do I create a Shortcode that returns text if domain is .com, not .co.uk
  61. Using preg_replace to separate gallery from the_content?
  62. Remove specific shortcode from get_the_content()
  63. How to display the site name in a WordPress page, or post
  64. Hide/show content starting in the middle of a paragraph
  65. Combining shortcode and get_template_part
  66. How can I put a wp_redirect into a shortcode?
  67. Escaping quotes from shortcode attributes
  68. Run visual composer code in php page
  69. short code output too early
  70. Shortcode in shortcode: How to append variable?
  71. Remove wptexturize from a shortcode?
  72. How can i put an array as variable in shortcode_atts?
  73. Autoembeds don’t work with paragraphs
  74. Table of Contents with a shortcode
  75. Dealing with Many Meta Values, 30+
  76. Create custom [sourcecode] shortcode, the right way?
  77. TED talks shortcode not working
  78. Allowing shortcodes inside attributes
  79. What is the best way to enable nested shortcodes?
  80. Tinymce – How to hook before or after live shortcodes rendering?
  81. How to customize a shortcode using the customizer
  82. Native “playlist” shortcode random playing… How?
  83. How to Output HTML tags in do_shortcode?
  84. List of all inbuilt WordPress shortcodes
  85. Nested Shortcode Detection
  86. Shortcode output always showing at top of page
  87. When using add_post_meta and update_post_meta, is there any way to give the individual arrays keys?
  88. Organizing shortcodes. How to display all of them and their attributes?
  89. How to detect if a Shortcode is being called on a page?
  90. How to get current page title inside a page itself in a shortcode and in page content
  91. What kind of object type is WP_Query?
  92. how to have the gallery shortcode output one single UL list instead of several DL?
  93. Implement If-ElseIf-Else-EndIf with short codes
  94. Short code to display a loop
  95. Using shortcode in Post title
  96. using html as shortcode attribute
  97. shortcode outputs first before the page content [duplicate]
  98. How to add ‘class’ attribute into shortcode [audio]?
  99. How can merge two arrays values in one array and save in database
  100. Make shortcode work with nested double quotes
Categories shortcode Tags array, meta-value, post-meta, shortcode
How to pass a variable for key/value pairs in an argument?
wp-cron function not running when activating the cron by form submit

Recommended Hostings

Cloudways: Realize Your Website's Potential With Flexible & Affordable Hosting. 24/7/365 Support, Managed Security, Automated Backups, and 24/7 Real-time Monitoring.

FastComet: Fast SSD Hosting, Free Migration, Hack-Free Security, 24/7 Super Fast Support, 45 Day Money Back Guarantee.

Recent Added Topics

  • Bug in translation system: load_theme_textdomain() returns true, files are available and accessible but the language defaults to english
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • Get the name of the template/*html file used
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
  • How to display the description of a custom post type in the dashboard?
  • Critical error on image display
  • Copying WP data and files into new install?
  • How to determine the DirectAdmin WordPress backup date?
  • How to get list of ALL tables in the database?
© 2026 Read For Learn
  • Database
    • Oracle
    • SQL
  • algorithm
  • asp.net
  • assembly
  • binary
  • c#
  • Git
  • hex
  • HTML
  • iOS
  • language angnostic
  • math
  • matlab
  • Tips & Trick
  • Tools
  • windows
  • C
  • C++
  • Java
  • javascript
  • Python
  • R
  • Java Script
  • jQuery
  • PHP
  • WordPress