Shortcode näkyy ja toimii vain kirjautuneena WP:iin
-
Olen tehnyt lapsiteeman functions.php tiedostoon alla olevan shortcoden, joka näkyy jostain syystä vain kirjautuneena WordPressin hallintaan. Miten shortcodet saa näkymään myös julkisesti sivustolla?
<?php
// Yhteystiedot, uusin
function wpb_postsbycategory() {
// the query
$the_query = new WP_Query( array( ’category_name’ => ’yhteystiedot’, ’posts_per_page’ => 1, ’orderby’ => ’post_date’, ’order’ => ’DESC’ ) );// The Loop
if ( $the_query->have_posts() ) {
$string .= ’<div class=”postsbycategory widget_recent_entries”>’;
while ( $the_query->have_posts() ) {
$the_query->the_post();$string .= ’<div>’.” .get_the_content() .'</div>’;
$string = apply_filters(’the_content’, $string);
$string = str_replace(’]]>’, ’]]>’, $string);
}
} else {
// no posts found
}
$string .= ’</div>’;return $string;
/* Restore original Post Data
wp_reset_postdata();*/
}
// Add a shortcode
add_shortcode(’yhteystiedot-koodi’, ’wpb_postsbycategory’);add_filter( ’widget_text’, ’shortcode_unautop’);
add_filter( ’widget_text’, ’do_shortcode’);
- The topic ‘Shortcode näkyy ja toimii vain kirjautuneena WP:iin’ is closed to new replies.