‘&’ causes an error in my shortcode when I list the content of the page

I would like to list the specified pages with my shortcode, but the problems are with the ‘$’ charachters.

function get_page_func( $atts )
    {
        extract(shortcode_atts( array(
                'title' => ''
        ), $atts ) );
        $page = get_page_by_title($title);

        $the_query = new WP_Query( 'page_id='.$page->ID );

        if ( $the_query->have_posts() ) {
            while ( $the_query->have_posts() ) {
                $the_query->the_post();
                $html = '<div class="row page-waypoint" id="'.$page->post_name.'"><div class="col-md-12"><h2>'.get_the_title().'</h2></div>'.get_the_content().'</div>';

            }
        }

        return do_shortcode($html);

        wp_reset_postdata();
    }

    add_shortcode( 'get_page', 'get_page_func' );

If I use [get_page title="Questions&Answers"], the shortcode doesn’t list the content of the Questions&Answers page, but lists every blog posts.
Do I use the wp_reset_postdata(); function properly?

Read More

Where is the problem?

Related posts

Leave a Reply

2 comments

  1. I had to use get_page_by_title( htmlspecialchars( $title ) ); to convert & to &amp;.

    get_page_by_title( html_entity_decode( $title ) ); did not work for me