Support » Developing with WordPress » Need help with checkbox “options”

  • Hi, guys…
    fiew days ago I found that there is an awesome option in wordpress get_option(‘sticky’) and now I want to change on an plugin that one with others checkboxes that already have on every post.
    example: I have an post sticky and when I get this code somewere it will get the sticky posts… and I want to add if there will be an other checkbox checked (like “Bonus” with id=”bonus”) and this post… without to be featured (sticky).

    now I have this code to imagine how is it:

    $aarl = get_option('sticky');
    $result_aarl       = array_intersect($aarl, $post_ID);
Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator bcworkz

    (@bcworkz)

    Where did you see this option? There is no “sticky” option in the options table by default. There is “sticky_posts”, which is an array of post IDs. So you can add any post ID to this array to make it sticky as well. Array intersect will isolate any ID that’s already there. The result will either be empty, or the post ID. Is that what you really want?

    Adding other check boxes is usually possible. Where do you want to add them? The check box status would need to be saved, then be used to alter applicable queries if that is what the check boxes are intended for. It’s not clear what you are really trying to do. Coding is very explicit, to get the help you want with coding, your description has to be explicit and complete.

    SonicxXx

    (@sonicxxx)

    on classipress. it uses the custom post type and there are “sticky” ads.
    The code that I put on my fist post is from an plugin that hooks with that command the sticky ads and relist them. I just want to add enouther checkbox (example:the-new-checkbox) on the post.php page while editing the ad and change from get_option('sticky') to get_option('the-new-checkbox') on the code of plugin.

    Moderator bcworkz

    (@bcworkz)

    Thanks for explaining further. We’re unable to help you in these forums with code related to commercial themes and plugins because the source code is not publicly accessible. I can only speak in general terms. If the plugin generating the meta box has an appropriate action hook, use it to output the necessary HTML.

    When checked, your checkbox’s name will be set in $_POST. Hook an action like “save_post” to check for this array element, and when set do the appropriate code to set or unset whatever options you need to.

    If there is no useful action, you could directly hack the plugin code, but you’ll lose your changes when the plugin is updated. You could copy the meta box code, give it a new name, alter as needed, then hide the original and use your version on the edit screen. Or you could make your own separate meta box to use in addition to the main one. More info on meta boxes is available in the Plugin Handbook. The handbook also has info on action hooks if you need help with that aspect. Hopefully this is enough to get you going on the right path. Good luck!

Viewing 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.