Home › Forums › Backend Issues (wp-admin) › Customize Admin Post List
I have a custom post type “issue” and relationship with custom post type “article”. What I want is, to create the issue cpt as a taxonomy for the article cpt, and showing it in article post list. When the users add new issue, so the taxonomy will updated it self. And the final result is, I can filtering the articles only based on the issue name.
I am using this code but not working
//Articles Filter by Issue
function restrict_articles_by_issue() {
global $wpdb;
$issues = $wpdb->get_col("
SELECT DISTINCT meta_value
FROM ". $wpdb->postmeta ."
WHERE meta_key = 'issue'
ORDER BY meta_value
");
?>
<label for="issue">Issues:</label>
<select name="issue_restrict_articles" id="issue">
<option value="">Show all</option>
<?php foreach ($issues as $issue) { ?>
<option value="<?php echo esc_attr( $issue ); ?>" <?php if(isset($_GET['issue_restrict_articles']) && !empty($_GET['issue_restrict_articles']) ) selected($_GET['issue_restrict_articles'], $issue); ?>>
<?php
$issue = get_post($issue);
echo $issue->post_title;
?>
</option>
<?php } ?>
</select>
<?php
}
add_action('restrict_manage_posts','restrict_articles_by_issue');
function posts_where( $where ) {
if( is_admin() ) {
global $wpdb;
if ( isset( $_GET['issue_restrict_articles'] ) && !empty( $_GET['issue_restrict_articles'] ) && intval( $_GET['issue_restrict_articles'] ) != 0 ) {
$issue_number = intval( $_GET['issue_restrict_articles'] );
$where .= " AND ID IN (SELECT post_id FROM " . $wpdb->postmeta ."
WHERE meta_key='issue' AND meta_value=$issue_number )";
}
}
return $where;
}
add_filter( 'posts_where' , 'posts_where' );
Anyone can help?
The topic ‘Customize Admin Post List’ is closed to new replies.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.