Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6022105
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T03:48:39+00:00 2026-05-23T03:48:39+00:00

Is it possible to filter out only the shortcode from the post and then

  • 0

Is it possible to filter out only the shortcode from the post and then run the shortcode?

My page looks like this:

[summary img="images/latest.jpg"]

This here is the summary

[/summary]

Lots of text here...

And i just want to display the shortcode on a specific page.

Tried using regular expressions, but they dont seem to work:

$the_query = new WP_Query('category_name=projects&showposts=1');

    //loop
    while ( $the_query->have_posts() ) : $the_query->the_post();
        echo '<b>';
        the_title();
        echo '</b>';
        echo '<p>';

        $string = get_the_content();

        if (preg_match("[\\[[a-zA-Z]+\\][a-zA-Z ]*\\[\/[a-zA-Z]+\\]]", $string , $matches)) {
            echo "Match was found <br />";
            echo $matches[0];
        }

        echo '</p>';
    endwhile;

Any idéas?

EDIT:

Found a temporary solution.

while ( $the_query->have_posts() ) : $the_query->the_post();

    $content = str_replace(strip_shortcodes(get_the_content()),"",get_the_content());               
    echo do_shortcode($content);

endwhile;

I saw that wordpress had a function for striping shortcodes but not for strip content. So i replaced the stripped content string from the whole post to get just the shortcode. The only bad thing about this that the shortcodes have to be in the beginning of the posts.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T03:48:40+00:00Added an answer on May 23, 2026 at 3:48 am

    use this regex

    preg_match('/\[summary[^\]]*](.*)\[\/summary[^\]]*]/uis', $string , $matches)

    $match[1] should be your text

    Edit: ok to match any combination of tags
    use

    /\[([^\]]+)\](.*?)\[\/\1\]/uis

    but if you have nested tags you might need to parse the matches again recursively. However if it is a wordpress free text i think you might get too complex cases that a simple script can handle

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am making a median filter, the problem is manipulating pixes are only possible
Is it possible to filter out subsets of the data that have small numbers
I want to filter out those with field not like '%_[0-9]+' , but it
Is it possible to filter the contents of a Listbox in a Windows Forms
Possible Duplicate: How do you implement a good profanity filter? I am developing a
Is it possible to write a servlet filter to take inspect HTTP response codes?
Is it possible to create a filter in a Drupal 6 View that is
Possible Duplicate: How do I calculate someone's age in C#? Maybe this could be
I am want to filter out messages that contain specified string. I used log4net.Filter.StringMatchFilter
This seems like such a simple task, but I'm having a hard time finding

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.