Question

Il y a quelque chose de bizarre dans un thème récent que j'ai développé.
À l'intérieur de la page de publication lorsque j'utilise $post->ID et get_the_ID() Il renvoie toujours le même identifiant qui appartient à l'un de mes messages!
Je me demande ce qui se passe là-bas? !!!

Éditer: J'ai trouvé la raison de ce comportement. Et c'est que j'ai créé un widget qui à l'intérieur j'utilise le WP_Query classe (vous pouvez voir le code à la fin) et je suppose qu'il remplace le Global $ POST.

Class TextAds étend 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;

    }

}

Pas de solution correcte

Licencié sous: CC-BY-SA avec attribution
Non affilié à wordpress.stackexchange
scroll top