Skip to content
Read For Learn
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP

Adding a meta box to determine the sidebar [closed]

Install metabox plugin and active:

/**** Add this code in your function.php ****/

$meta_boxes[] = array(
    'id' => 'post_sidebar',         
    'title' => 'post Sidebar',      
    'pages' => array('post'),       
    'priority' => 'low',            
    'fields' => array(          
            array(
                'name' => 'Post Sidebar',               
                 'id' => 'post_sidebar',        
                 'type' => 'select',                            
                 "options" => array( "0" => "OFF", "1" => "Left side", "2" => "Right Side"),
            ),
        )
);
if ( class_exists( 'RW_Meta_Box' ) )
{
    foreach ( $meta_boxes as $meta_box )
    {
        new RW_Meta_Box( $meta_box );
    }
}

/**** after single.php on get value using this one option ****/  

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

if($sidebar_value == 1 && $sidebar_value!=0){
    // Add sidebar code for left side
}

if($sidebar_value=='2' && $sidebar_value!=0){
    // Add sidebar code for right side
}

enter image description here

Related Posts:

  1. How can I retrieve multiple get_post_meta values efficiently?
  2. How to batch update post content with custom post meta value
  3. Using radio button meta data from a custom meta box
  4. Meta value does not save for scheduled posts
  5. How to I retrieve the ID from the Posts page?
  6. How to save meta checkbox WordPress
  7. Updating post meta for checkbox
  8. How can I tell if a post has been published at least once?
  9. Simple Custom Metabox Not Saving
  10. How to check if post meta key exists or not in wordpress database
  11. How to add category to: ‘wp-admin/post-new.php’?
  12. Code to make a post sticky
  13. Display Random Author with Details in Sidebar
  14. How to allow hidden custom fields to be added from wp-admin/post.php?
  15. Can I force a metabox to be in one column?
  16. How to add a new tab to page editor
  17. Listen to Post action
  18. Export WordPress Posts and Meta Information in CSV format
  19. Delete duplicated wp_postmeta record
  20. How to add metabox for post of specific category
  21. Getting the Next and Previous Posts Titles in the Sidebar?
  22. Will a large postmeta table slow a site down?
  23. Update all posts automatically when using post_meta
  24. upload image in a meta box
  25. Change slug with custom field
  26. Post X of Y in single.php / sidebar.php
  27. Better post meta efficiency?
  28. Setting post meta data to random value during post status transition / on publish
  29. meta_box or custom_field as a second tinymce post-instance?
  30. Edit meta data does’t work with custom sql
  31. 1 column admin screen options – move submitdiv to bottom
  32. multicheck box for post metabox
  33. Create A Metabox For A Custom Field
  34. Human Time Diff, change mins to minutes
  35. Change post format using custom field
  36. Have save_post write to database image meta [closed]
  37. Does WP get all post_meta on POST page?
  38. Display all posts under child sub category in sidebar on post page?
  39. Sanitizing `wp_editor();` Values for Database, Edit, and Display
  40. What Can I Use To Add A Custom Button Between Publish button and Move To Trash?
  41. Exporting Data from WordPress into a flat table
  42. Adding Multiple Values to a Post Meta Key
  43. Load posts into sidebar and paginate via ajax?
  44. How to show post(excerpt) from specific category on wp page?
  45. How to show video from specific category on sidebar?
  46. Save list from a custom meta box?
  47. Using Custom Posts with Metaboxes and Drop-downs
  48. WordPress menu that shows all posts in a certain category like w3schools
  49. How can I hide the sidebar from a specific post?
  50. PHP Notice error (when on 404 page)
  51. What Is meta_id In wp_postmeta?
  52. Checking if a post with certain meta value exists
  53. How to permanently delete a post meta entry?
  54. Add custom field automatically (add_post_meta) with value based on number of words of article
  55. Automatic value for custom fields for posts
  56. How to generate numbers indistinguishable for the IDs of the posts
  57. Modify WP_Post before processing
  58. How to rename “Publish” metabox title in post screen
  59. Understanding and using metaboxes in posts
  60. Save re-arranged draggable post items to wordpress database
  61. Sidebar links for different pages
  62. I would like to give special promotion for the first 100 posts in my blog? Can anyone tell me how to do that?
  63. Change post_date to post_modified date on post template?
  64. Show all posts in sidebar in single.php
  65. Converting a dynamic piece of code using WordPress Loop into a static one using Post ID
  66. Dashboard :10 Last draft page and 10 last pending review page (metabox)
  67. Get latest posts from WordPress site without header, menu and sidebar
  68. Post-ID in url differs from $post->ID
  69. How can I sort posts by the date and a custom meta field?
  70. is there a way to show the the post title after the image?
  71. Get Meta Key Value While Saving Post
  72. Adding custom fields to bbpress reply form
  73. Force the “Choose from the most used tags” meta box section to always be expanded
  74. Can wordpress post and sidebar remain visible after scroll?
  75. Custom Posts Query and meta_query Sort Order
  76. How to compare two posts including their meta fields on a scalable base?
  77. Getting value from get_post_custom
  78. WordPress Sidebar menu for posts based on date – guidance needed
  79. Calling Different Custom Post Timestamps in a table
  80. Simultaneous admin updates causes custom fields to not update
  81. Is it possible to paste a link without tags and make it directly a link in a post?
  82. Cannot retrieve a custom RSS field from posts
  83. Saving custom fields to a custom taxonomy
  84. How to automate featured posts number? [duplicate]
  85. 2 dynamic sidebars registered, not showing up
  86. Customize rel=canonical tag for single blog post
  87. Change all author links in Blog roll
  88. Sidebar show posts by current category also in single post
  89. How to calculate the average of a post meta value(Numeric) of a specific author
  90. Is there any way to tell when wp_postmeta has been updated?
  91. Hide custom metabox value from custom fields
  92. Is there a way to create a meta box that can be added multiple times to a post dynamically?
  93. Get post meta retrieving wrong value
  94. wpColorPicker – problem with implementation to post meta
  95. Upload attachment from external site
  96. Change post author without using wp_update_post()
  97. Show metabox value last post excerpt, title and link
  98. if in category but only with post meta
  99. wp_query with ajax
  100. Update post meta within save_post action
Categories posts Tags metabox, post-meta, posts, sidebar
How to hide Newsletter plugin submenus from the Dashboard?
If $var is empty, return 404.

Recommended Hostings

Cloudways: Realize Your Website's Potential With Flexible & Affordable Hosting. 24/7/365 Support, Managed Security, Automated Backups, and 24/7 Real-time Monitoring.

FastComet: Fast SSD Hosting, Free Migration, Hack-Free Security, 24/7 Super Fast Support, 45 Day Money Back Guarantee.

Recent Added Topics

  • Bug in translation system: load_theme_textdomain() returns true, files are available and accessible but the language defaults to english
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • Get the name of the template/*html file used
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
  • How to display the description of a custom post type in the dashboard?
  • Critical error on image display
  • Copying WP data and files into new install?
  • How to determine the DirectAdmin WordPress backup date?
  • How to get list of ALL tables in the database?
© 2026 Read For Learn
  • Database
    • Oracle
    • SQL
  • algorithm
  • asp.net
  • assembly
  • binary
  • c#
  • Git
  • hex
  • HTML
  • iOS
  • language angnostic
  • math
  • matlab
  • Tips & Trick
  • Tools
  • windows
  • C
  • C++
  • Java
  • javascript
  • Python
  • R
  • Java Script
  • jQuery
  • PHP
  • WordPress