Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use wp_dropdown_categories() to display select categories field. Display each meta box setting per line #3

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 11 additions & 18 deletions class-category-sticky-post.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ public function category_sticky_post_display( $post ) {
wp_nonce_field( plugin_basename( __FILE__ ), 'category_sticky_post_nonce' );

// Get the category dropdown and the checkbox for displaying the border
$html = $this->get_categories_list( $post );
$html .= $this->get_border_checkbox( $post );
$html = '<p>' . $this->get_categories_list( $post ) . '</p>';
$html .= '<p>' . $this->get_border_checkbox( $post ) . '</p>';

echo $html;

Expand Down Expand Up @@ -383,22 +383,15 @@ private function get_sticky_query( $category ) {
* @since 2.0.0
*/
private function get_categories_list( $post ) {

// First, read all the categories
$categories = get_categories();

// Build the HTML that will display the select box
$html = '<select id="category_sticky_post" name="category_sticky_post">';
$html .= '<option value="0">' . __( 'Select a category...', 'category-sticky-post' ) . '</option>';
foreach( $categories as $category ) {
$html .= '<option value="' . $category->cat_ID . '" ' . selected( get_post_meta( $post->ID, 'category_sticky_post', true ), $category->cat_ID, false ) . '>';
$html .= $category->cat_name;
$html .= '</option>';
}
$html .= '</select>';

return $html;

$category_sticky_post = get_post_meta( $post->ID, 'category_sticky_post', true );

return wp_dropdown_categories( array(
'echo' => false,
'id' => 'category_sticky_post',
'name' => 'category_sticky_post',
'show_option_none' => __( 'Select a category&hellip;', 'category-sticky-post' ),
'selected' => $category_sticky_post,
) );
}

/**
Expand Down