WordPress restituisce lo stesso ID post ogni volta ovunque!
-
31-10-2019 - |
Domanda
C'è qualcosa di strano in un tema recente che ho sviluppato.
All'interno della pagina post quando uso $post->ID
e get_the_ID()
Restituisce sempre lo stesso ID che appartiene a uno dei miei post!
Mi chiedo cosa sta succedendo lì? !!!
Modificare: Ho trovato il motivo dietro questo comportamento. Ed è che ho creato un widget che al suo interno uso il WP_Query
Classe (puoi vedere il codice alla fine) e immagino che stia sovrascrivendo il Global $ Post.
class textAds estende wp_widget {
function TextAds(){
$widget_ops = array( 'description' => __( "نمایش تبلیغات متنی", 'appthemes') );
$this->WP_Widget('textads', __('تبلیغات متنی', 'appthemes'), $widget_ops);
}
function widget($args, $instance){
//global $userdata;
extract($args);
if ( !empty($instance['title']) ) {
$title = $instance['title'];
} else {
$title = 'تبلیغات متنی';
}
echo $before_widget;
$title = apply_filters('widget_title', $title, $instance, $this->id_base);
$term = get_term_by( 'slug','text', 'ad_cat' );
$text_query = new WP_Query( array('post_type' => APP_POST_TYPE, APP_TAX_CAT => $term->slug, 'ignore_sticky_posts' => 1 ));
?>
<h2 class="widgettitle"><?php echo $title; ?></h2>
<div class="clr"></div>
<?php while ( $text_query->have_posts() ) : $text_query->the_post(); ?>
<div class="ad0text"><a href="<?php
//$url = get_post_meta(get_the_ID(),'cp_url',true);
if(stripos($url,'http://') === false){
$url = 'http://'.$url;
}
echo $url; ?>"><?php the_title(); ?></a></div>
<div class="divider"></div>
<?php endwhile; ?>
<?php
echo $after_widget;
}
function form( $instance ) {
?>
<p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('عنوان ابزارک:', 'appthemes') ?></label>
<input type="text" class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" value="<?php if (isset ( $instance['title'])) {echo esc_attr( $instance['title'] );} ?>" /></p>
<?php
}
function update( $new_instance, $old_instance ) {
$instance['title'] = strip_tags(stripslashes($new_instance['title']));
return $instance;
}
}
Nessuna soluzione corretta
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a wordpress.stackexchange