2012-07-12 49 views
1

由於我已經建立了我的模板的方式,我需要有一個字符串的URL格式如下:如何將我的數組查詢轉換爲wordpress中的字符串查詢?

$the_query = array('post_type' => 'product', 'taxonomy' => 'product_types', 'term' => 'solar-panel') 

我覺得像

$the_query = new WP_Query('post_type=product&taxonomy=product_types&term=solar-panel&showposts=2') 

但這不是由於工作到分類學本身就是一個數組這一事實。謝謝。

+0

它確定它實際上是工作,我的錯誤 – Nicola 2012-07-12 15:45:43

回答

0

您的模板是否允許您在WP_Query之外設置選項?

$args=array(
    'post_type' => 'product', 
    'taxonomy' => 'product_types', 
    'term' => 'solar-panel', 
); 

$the_query = new WP_Query($args); 

如果不是,那麼你的模板怎麼樣不會讓你這樣做?你可以發佈一些代碼嗎?

+0

沒關係,我設法以字符串格式。我想我是在想,如果我按照你發佈的方式來完成,那麼我將不得不做一個foreach循環,但我不這樣做?它仍然可以是<?php while($ the_query - > have_posts()):$ the_query - > the_post(); ?> – Nicola 2012-07-13 08:33:13

相關問題