Ich bekomme einen wirklich seltsamen Fehler. Ich bekomme die gleichen Kommentare von einem bestimmten Beitrag, der die “Hallo Welt” für jeden einzelnen Beitrag ist! Aber wenn ich etwas Code für ein neues Posts-Widget entferne, das ich zu erstellen versuche, verschwindet dieser Bug … hier ist der Code des letzten Posts-Widgets:
class Hype_Recent_Posts extends WP_Widget { public function __construct() { parent::__construct( 'hype_rp', // Base ID __('Paradox Recent Posts', 'hype'), // Name array( 'description' => __( 'Display your recent posts, with a Thumbnail.', 'hype' ), ) // Args ); } public function widget( $args, $instance ) { $title = apply_filters( 'widget_title', $instance['title'] ); $no_of_posts = apply_filters( 'no_of_posts', $instance['no_of_posts'] ); echo $args['before_widget']; if ( ! empty( $title ) ) echo $args['before_title'] . $title . $args['after_title']; // WP_Query arguments $qa = array ( 'post_type' => 'post', 'posts_per_page' => 5, 'offset' => 0, 'ignore_sticky_posts' => 1 ); // The Query $recent_articles_wtb = new WP_Query( $qa ); if($recent_articles_wtb->have_posts()) : ?> have_posts()) : $recent_articles_wtb->the_post(); ?> - <a href="https://wordpress.stackexchange.com/questions/178594/all-posts-have-the-same-comments/"> <a href="https://wordpress.stackexchange.com/questions/178594/all-posts-have-the-same-comments/"><img src="https://wordpress.stackexchange.com/questions/178594/all-posts-have-the-same-comments//images/9viqf41.jpg"> <a href="https://wordpress.stackexchange.com/questions/178594/all-posts-have-the-same-comments/">
Oops, there are no posts.
<label for="get_field_id( 'title' ); ?>"> <input class="widefat" id="get_field_id( 'title' ); ?>" name="get_field_name( 'title' ); ?>" type="text" value="" /> <label for="get_field_id( 'no_of_posts' ); ?>"> <input class="widefat" id="get_field_id( 'no_of_posts' ); ?>" name="get_field_name( 'no_of_posts' ); ?>" type="text" value="" />
- WP_Query mit page_ids in Argumenten ohne Ergebnis
- Wie wird der Seiteninhalt in einer Seitenvorlage angezeigt?
- Verwenden Sie das erweiterte benutzerdefinierte Feld zum Hochladen von Dateien. Wie lade ich die Datei-URL ein?
- Holen Sie den gesamten Inhalt je nach Sprache auf eine "einzelne Seite"
- meta_query funktioniert nicht richtig
- Abfrage Posts und Rückgabe von XML
<?php } public function update( $new_instance, $old_instance ) { $instance = array(); $instance['title'] = ( ! empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : ''; $instance['no_of_posts'] = ( ! empty( $new_instance['no_of_posts'] ) ) ? strip_tags( $new_instance['no_of_posts'] ) : '5'; if ( is_numeric($new_instance['no_of_posts']) == false ) { $instance['no_of_posts'] = $old_instance['no_of_posts']; } return $instance; } } add_action( 'widgets_init', 'register_hype_widget' ); function register_hype_widget() { register_widget( 'Hype_Recent_Posts' ); }
Sie stampfen mit Ihrem Plugin auf die weltweiten WordPress-Posts.
Führe deinen wp_query-Anruf aus und rufe dann an
$recent_articles_wtb->the_post();
bedeutet, dass Sie später (nach Ihrer Schleife) anrufen möchten
wp_reset_postdata(); # Thanks Milo
Das sollte die globalen $ current_post- und $ post-Objekte zurücksetzen.