Your solution has helped me find an answer to my own problem of getting the attribute of a certain shortcode, but I fear there may be an issue with your approach.
You’re using preg_match
to check the post_content
, which will only return 1 match. If you have a post that has multiple shortcodes in it, it will only return the first one, which may not be the one you’re looking for.
Instead, you should use preg_match_all
, then loop through the regex_matches
array to check for the shortcode you need.
Also, you don’t need to use str_replace
to remove the quotes from the string. WordPress has a built-in function shortcode_parse_atts
which takes that a string of parameters (in your case it would be $regex_matches[3]
) as an argument and outputs an array. This would also spare you the use of wp_parse_args
function.
Related Posts:
- Split Content and Gallery
- How to return loop contents
- Return vs Echo Shortcode
- as a shortcode within the loop?
- Adding shortcode closing tag after a loop
- What are the disadvantages of using global variable?
- Displaying terms based on loop posts?
- Missing image in gallery shortcode in custom feed
- Shortcode with a foreach and arguments
- Output loop leveraged shortcode twice on one page
- Custom Loop Using Shortcode in Custom Page Template
- Shortcode in posts called by ajax is not working
- Trying to get property of non-object in shortocde
- WordPress shortcode in content, output in sidebar?
- Query posts only with actual text content (not including shortcode or images)
- How to put a block of code between [shortcode][/shortcode] in do_shortcode()?
- How can I pass additional params to a shortcode while in a loop?
- Get a Post Loop based on Logged in User information into a Shortcode
- How to add pagination in Terms
- Split Content and Gallery
- Shortcode for pulling specific Post Title outside loop when ID is passed in
- Have multiple loops on a page appear after/between page content
- Using shortcode within shortcode with dynamic variable
- How wp maps urls into files
- Jquery Slider for profile template
- Get excerpt using get_the_excerpt outside a loop
- Should I use loop in the single.php file?
- How can I custom order the results from wp_list_categories?
- Display all authors and their only one latest post
- Remove comma from last item output from loop
- Page template not displaying
- How would I create a shortcode to display a custom post within a page or regular post?
- Can I use both a custom excerpt and a trimmed excerpt?
- How to get_template_part using AJAX?
- How can I modify the loop from a plugin without wiping out other filters?
- I’ve been out of the loop since 2.8. What did I miss?
- Loop first six posts in carousel, next eight in grid
- Infinite blog loop
- One custom loop with condition to check child posts
- Loop get_theme_mod
- Move sticky posts down in main loop
- Why only one post (and no pagination) on this variation of the loop?
- Loop in Related Posts WordPress
- Conditional query that displays on Woo product attribute pages
- Template structure
- Listing subpages title and content and styling the first iteration differently
- Cannot retieve the_content() and the_author() – both returning empty strings
- How to order by multiple fields using standard query_posts?
- How to get the excerpt for is_home() outside of the loop isn’t working
- Make loop alphabetical
- How to check if a product is purchased within the last 365 days before displaying something
- How do I get my loop.php to properly paginate?
- Loop through ACF taxonomies and output associated posts
- How to get user ID’s from multiple usernames?
- How to display first post
- Pagination on custom post type on front-page.php
- get_template_part() Not Working in Loop
- CPT while loop not working
- Problem with Front-Page.php loading recent posts
- Where to add offset?
- How to synchronize The Loop with the max post per page?
- How to add a byline to all the pages?
- How do i create a list-posts-page?
- Exclude posts based on an array
- Displaying member join date on page
- Ascending order has strange effects on wordpress loop
- List ALL posts by author on author archive
- get post images to link to external sources
- Using is_page_template inside loop
- How to show the last article in a different way in my blog?
- Can’t limit posts_per_page in loop
- Slug is changing when I use WP_Query in a metabox of a post
- Check to see if a field is within an array in twig
- Custom loop not working in singular.php, working in other pages
- Loop Posts Outside of WordPress Installation
- Strange problem with wp_get_attachment_image_src database (db) query count
- How to include posts from one category, into a separate category of posts?
- how do i make this loop work
- Archive sorted by month – separate
- Making a specific page wordpress compatable that is not index
- Humanmade | Custom meta box class: How to display a repeatable meta box group?
- Can’t print out returned value
- change the_content images for different sizes (Desktop, tablet, mobile)?
- Get query result before posts are displayed?
- WordPress Group By Problem
- Nested loop called with shortcode duplicating the content above the main loop
- Home page loop with pagination problem
- WooCommerce custom loop pagination on front page
- Eliminate duplicates in a foreach loop [closed]
- Tag custom loop show posts
- While loop inside another while loop
- Problem with ms-thumb-frame-selected class in Master Slider
- I want the first post on my home page to be lengthier than the rest (example included)
- Loop with Custom Post Type Taxonomies and Interstitial Code
- Question about custom plugin
- loop mix my child-category and parent-category
- How can you make it so the comment box shows on some pages or posts but not all?
- Insert multiple custom components after x-number of posts
- How to get files from loop for zip
- Divide loop into several columns based on post custom field and enable infinite scrolling