Domanda

Sto usando il PhotoSmash plugin per consentire agli utenti di caricare le proprie immagini e votare su di loro, e funziona benissimo. Su una delle mie pagine io uso il seguente codice di elencare i post che hanno una certa categoria:

    <?php
if (is_page() ) {
$category = get_post_meta($posts[0]->ID, 'category', true);
}
if ($category) {
  $cat = get_cat_ID($category);
  $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
  $post_per_page = -1; // -1 shows all posts
  $do_not_show_stickies = 1; // 0 to show stickies
  $args=array(
    'category__in' => array($cat),
    'orderby' => 'date',
    'order' => 'ASC',
    'paged' => $paged,
    'posts_per_page' => $post_per_page,
    'caller_get_posts' => $do_not_show_stickies
  );
  $temp = $wp_query;  // assign orginal query to temp variable for later use   
  $wp_query = null;
  $wp_query = new WP_Query($args); 
  if( have_posts() ) : 
        while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
        <section class="vote6" id="post-<?php the_ID(); ?>">
          <?php the_content(); ?>
          <section class="voter">
              <?php DisplayVotes(get_the_ID()); ?>
          </section>
        </section>
    <?php endwhile; ?>
  <?php else : ?>

        <h2 class="center">Not Found</h2>
        <p class="center">Sorry, but you are looking for something that isn't here.</p>
        <?php get_search_form(); ?>

    <?php endif; 

    $wp_query = $temp;  //reset back to original query

}  // if ($category)
?>

Questa grande opera così, tranne quando viene attivato il plugin PhotoSmash. Ottengo il seguente errore:

Fatal error: chiamata a un get funzione membro () su un non-oggetto in \ nas-001 \ winspace004 \ 10-3mpromos.ca \ www \ carcrazy \ wp-includes \ query.php sulla linea 27

Linea 27 è return $wp_query->get($var); Il problema è da qualche parte dentro di BWB-photosmash.php nella cartella principale del plugin, ma non riesco a capire dove. Qualcun altro ha incontrato questo problema?

È stato utile?

Soluzione

Non v'è alcuna necessità di oggetto $wp_query juggle, conservarlo in temperatura, ecc E 'raramente buona idea direttamente pasticciare con importanti variabili globali, a meno che non è assolutamente necessario.

Si può solo creare il proprio variabile arbitraria e init con il nuovo WP_query

$some_variable = new WP_Query($args);

e così via.

Inoltre non dimenticate di pulitura dopo con wp_reset_query() .

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a wordpress.stackexchange
scroll top