$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>Custom shortcode is causing a WSOD|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

Custom shortcode is causing a WSOD

matteradmin10PV0评论

I have written a custom shortcode (see below) and placed it in the functions.php file of my child theme.

The aim of the shortcode is to retrieve the title of a previously created custom post. In this case the custom post type I created is titled 'publications_test' from the ID of the post.
For example, [testshorctode id=427] would output the title of the post whose ID is 427. Unfortunately, the code is producing a WSOD and I'm not sure where I am going wrong.

Any help would be greatly appreciated. I am by no means a web developer, so I apologize for any obvious error.

function register_shortcodes() {
add_shortcode( 'testshortcode', 'testshortcode_function' );
}

add_action( 'init', 'register_shortcodes' );

function testshortcode_function($atts) {
    extract( shortcode_atts(
        'post_type' => 'publications_test',
        'post_status' => 'publish'
        'id' => '',
    );

            global $post;

    $string = '';
    $query = new WP_Query( $atts );
    if( $query->have_posts() ){
        $string .= '<ul>';
        while( $query->have_posts() ){
            $query->the_post();
            $string .= '<li>' . get_the_title() . '</li>';
        }
        $string .= '</ul>';
    }
    wp_reset_postdata();
    return $string;
}

I have written a custom shortcode (see below) and placed it in the functions.php file of my child theme.

The aim of the shortcode is to retrieve the title of a previously created custom post. In this case the custom post type I created is titled 'publications_test' from the ID of the post.
For example, [testshorctode id=427] would output the title of the post whose ID is 427. Unfortunately, the code is producing a WSOD and I'm not sure where I am going wrong.

Any help would be greatly appreciated. I am by no means a web developer, so I apologize for any obvious error.

function register_shortcodes() {
add_shortcode( 'testshortcode', 'testshortcode_function' );
}

add_action( 'init', 'register_shortcodes' );

function testshortcode_function($atts) {
    extract( shortcode_atts(
        'post_type' => 'publications_test',
        'post_status' => 'publish'
        'id' => '',
    );

            global $post;

    $string = '';
    $query = new WP_Query( $atts );
    if( $query->have_posts() ){
        $string .= '<ul>';
        while( $query->have_posts() ){
            $query->the_post();
            $string .= '<li>' . get_the_title() . '</li>';
        }
        $string .= '</ul>';
    }
    wp_reset_postdata();
    return $string;
}
Share Improve this question edited Jun 8, 2017 at 19:44 avpaderno 1116 bronze badges asked Jun 8, 2017 at 16:09 Chris GChris G 1 1
  • in wp_config.php set define( 'WP_DEBUG', true ); to help figure out white screen problems. that's a good place to start with debugging wordpress php problems – mrben522 Commented Jun 8, 2017 at 17:36
Add a comment  | 

1 Answer 1

Reset to default 2
 extract( shortcode_atts(
        'post_type' => 'publications_test',
        'post_status' => 'publish'
        'id' => '',
    );

The above is wrong. You have an array inside that function but it's not in an actual array. Try this instead:

 extract( shortcode_atts(array(
        'post_type' => 'publications_test',
        'post_status' => 'publish',
        'id' => '',
    ), $atts, 'testshortcode');

shortcode atts

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far