admin管理员组文章数量:1024016
To make a long story short, I have a custom post type called artworks
with these meta fields:
title
catalog_no
artist_key
I have a second custom post type called artists
with these meta fields:
artist_key
artist_firstname
artist_lastname
Obviously, the artist_key
field is used to relate the artist to their works. It contains alphanumeric strings such as "anvcih5-8745".
On category archives pages such as , I want to sort the results by artist_lastname.
In SQL I believe I would achieve this by doing an INNER JOIN, but I'm struggling to understand how to achieve the same thing in Wordpress.
I've figured out that I can add a posts_join filter that will allow me to join to another table. I have written the following hook and confirmed that it's firing on the correct page:
function archives_artwork_join($join)
{
if ( !is_admin() ) {
$qo = get_queried_object();
if ($qo->name == 'sculpture') {
// modify $join here
}
return $join;
}
}
add_filter( 'posts_join', 'archives_artwork_join' );
But, I don't know how to write the JOIN statement. And I don't even know whether I am on the right track with this approach.
Am I on the right track here, or is there a better approach I could take to sort the artworks category archives by artist last name?
To make a long story short, I have a custom post type called artworks
with these meta fields:
title
catalog_no
artist_key
I have a second custom post type called artists
with these meta fields:
artist_key
artist_firstname
artist_lastname
Obviously, the artist_key
field is used to relate the artist to their works. It contains alphanumeric strings such as "anvcih5-8745".
On category archives pages such as , I want to sort the results by artist_lastname.
In SQL I believe I would achieve this by doing an INNER JOIN, but I'm struggling to understand how to achieve the same thing in Wordpress.
I've figured out that I can add a posts_join filter that will allow me to join to another table. I have written the following hook and confirmed that it's firing on the correct page:
function archives_artwork_join($join)
{
if ( !is_admin() ) {
$qo = get_queried_object();
if ($qo->name == 'sculpture') {
// modify $join here
}
return $join;
}
}
add_filter( 'posts_join', 'archives_artwork_join' );
But, I don't know how to write the JOIN statement. And I don't even know whether I am on the right track with this approach.
Am I on the right track here, or is there a better approach I could take to sort the artworks category archives by artist last name?
本文标签: wp querySort custom post archives by a meta value from a different custom post type
版权声明:本文标题:wp query - Sort custom post archives by a meta value from a different custom post type? 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745607570a2158814.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论