2014-07-21 77 views
2

上下文:如何向数组添加多个值?

我有以下代码,我正在尝试修复。此代码会过滤我网站上的相册(自定义wordpress文章称为“freealbums”)。

的代码过滤通过艺术家的freealbums(自定义后类型,称为“艺术家”)和代码工作不错,但我试图做一个过滤器,让人们进行排序freealbums邮寄类型:

artist, upcomingartist and producer 

而不仅仅是艺术家的帖子类型,但我似乎不能添加多个帖子类型,以此代码并使其工作。

if(isset($_GET['a']) && intval($_GET['a']) != 0) { 

    $atts = themex_get_query(themex_get_posts('freealbum',array('ID'),-1, array('artists','upcomingartist'=>$_GET['a'])), $limit, $paged); 

} else { 

    $atts = array(
    'post_type'  =>'freealbum', 
    'posts_per_page' => $limit, 
    'paged'   => $paged, 
    'meta_key'  => '_thumbnail_id', 
); 

} 

query_posts($atts); 

这里是我做了尝试,并添加另一篇文章类型:

if(isset($_GET['a']) && intval($_GET['a']) !=0) { 

    $atts=themex_get_query(themex_get_posts('freealbum',array('ID'),-1, array('artists','upcomingartist'=>$_GET['a'])), $limit, $paged); 

} else { 
    $atts=array(
    'post_type'  =>'freealbum', 
    'posts_per_page' => $limit, 
    'paged'   => $paged, 
    'meta_key'  => '_thumbnail_id', 
); 
} 

query_posts($atts); 

正如你所看到的一切,我改变了下面的一段代码

array('artists'=>$_GET['a'])), 

为了这

array('artists','upcomingartist'=>$_GET['a'])), 

我以为这可以工作,但对于某些WEIRD原因,过滤器现在可以使用upcomingartist发布类型,但它停止使用艺术家发布类型。

不知道我在做什么错..请帮助!

+1

,你能否告诉这个函数的内容:' themex_get_posts()'? – Darren

回答

0

尝试把两个过滤器(目前你是upcomingartist过滤并通过怪异0 => 'artists'第二过滤器):

- array('artists','upcomingartist'=>$_GET['a'])), 
+ array('artists'=>$_GET['a'],'upcomingartist'=>$_GET['u'])), 

要在upcomingartist过滤使用以下命令:

array('upcomingartist'=>$_GET['u']) 

希望它有帮助。

+0

我尝试了你的建议和艺术家过滤器的作品,但即将到来的艺术家似乎仍然不工作 这里是我查询的完整代码 'if(isset($ _ GET ['a'])&& intval $ _GET [ '一'])!= 0){ \t $ atts = themex_get_query(themeal_get_posts('freealbum',array('ID'), - 1,array('artists'=> $ _ GET ['a'],'comingartist'=> $ _ GET [ 'u'])),$ limit,$ paged); }否则{ \t $的ATT =阵列( \t \t 'post_type'=> 'freealbum', \t \t 'posts_per_page'=> $限制, \t \t '寻呼'=> $寻呼, \t \t“meta_key '=>'_thumbnail_id', \t); } query_posts($ atts);' – skapaid

+0

你可以在这里看到一个例子[link](http://www.bamofficial.com/free-downloads) – skapaid

+0

很明显,你应该提供'comingartist'作为'u'在你的'GET'请求中工作。没有木匠魔术师。如果你想检索只有**的只有**的专辑,那么这个过滤器应该是:array('comingartistist'=> $ _ GET ['u'])''。 – mudasobwa

0

array_push - 将一个或多个元素到数组

$stack = array("orange", "banana"); 
array_push($stack, "apple", "raspberry"); 
print_r($stack); 

结束在你的代码:

array_push($someArray['upcomingartist'], $_GET); 

LINK