how to i get shortcode outside of wordpress?

how can i get shortcode outside of wordpress?

this is my code

<?php 
require($_SERVER['DOCUMENT_ROOT'] . '/wp-load.php'); 
$args = array(
    'posts_per_page' => 10 // Specify how many posts you'd like to display
);
$latest_posts = new WP_Query( $args );  
if ( $latest_posts->have_posts() ) {
    while ( $latest_posts->have_posts() ) {
        $latest_posts->the_post();
if (preg_match_all ("#\[scode\](.+)\[\/scode\]#", the_content(), $matches, PREG_SET_ORDER)) {
echo $matches[1];
};
?>

and this is my content

[scode]hare is my shortcode[/scode]
Lorem Ipsum is simply dummy text of the printing and typesetting industry.

Lorem Ipsum has been the industry’s standard dummy text ever since the 1500s,

when an unknown printer took a galley of type and scrambled it to make a type specimen book

anyone can help plz...

Answers


If I understand your question correctly, you should use do_shortcode('[shortcode_name]'). It returns a string, so you call it like : <?php echo do_shortcode('[shortcode_name]'); ?>.

In your example, you can probably do something like:

<?php 
    require($_SERVER['DOCUMENT_ROOT'] . '/wp-load.php'); 
    $args = array(
        'posts_per_page' => 10 // Specify how many posts you'd like to display
    ;
    $latest_posts = new WP_Query( $args );  
    if ( $latest_posts->have_posts() ) {
        while ( $latest_posts->have_posts() ) {
            $latest_posts->the_post();
    if (preg_match_all ("#". do_shortcode('[scode]') ."(.+)". do_shortcode('[scode]') ."#", the_content(), $matches, PREG_SET_ORDER)) {
    echo $matches[1];
    };
?>

That's possible. There's a composer package that allows you to create wordpress like shortcodes in any PHP application: https://github.com/maiorano84/shortcodes

You can find a tutorial here: https://www.codediesel.com/php/adding-wordpress-like-shortcodes-to-your-web-applications/


Need Your Help

ejb 3 :is it OK to make all relationships birectional?

hibernate orm jpa

Whenever i do OR mapping, i make all relationships bidirectional. That is, i totally avoid unidirectional relationships.