how to register / add multiple options into one field in wordpress?

How can I register or add multiple options into one field. For example, we save a logo in get_options() by registering the setting and adding fields by add_settings_field() function and we output it accordingly. But what if we want to save multiple options into one field, like we have an option on our page called "Select your favourite colour" and there are check-boxes with different colours and user needs to select multiple colours (not a single colour) then how would …
Category: Web

Best possible way to get all options

I need to provide a list of all options set via plugins etc to remote calls. There is a plugin WP API Options but it hardly does the job. There are two possible ways (that I know of) to get a list of all options set in the blog/site: Use $wpdb to run a query like so: $option_names = $wpdb->get_col( "SELECT DISTINCT option_name FROM $wpdb->options WHERE option_name NOT LIKE '_transient_%'" ); Use wp_load_alloptions() Which one of these two would be …
Category: Web

How to set different color in a select box due to selection with css

I have a select box with 2 options. In the selct area the options are green for 1 red for 2 I had been able to set green also as the color for the predefined option. Now I would like to change this due to the incoming selection. That means, if someone has 1 as predefined selection the color of the appearing conent of the shown select box should be green and if some has 2 as redefined selection the …
Category: Web

save_post_{CPT} not updating the 'sticky_posts' option

add_action( "save_post_{CPT}", 'update_sticky', 15, 1 ); function update_sticky( $post_id ) { $stickies = get_option( 'sticky_posts' ); if ( ! in_array( $post_id, $stickies ) ) { $stickies[] = $post_id; update_option( 'test', $stickies); update_option( 'sticky_posts', $stickies ); } } It does work for test option I created for testing, but it doesn't work for existing sticky_posts option, although everything is the same. It does work for both if I hardcode the $post_id, like: $stickies[] = 123; Tried it in functions.php file, as …
Category: Web

WP_Options ID high

I have a site where the options_id field in the wp_options table has grown very, very large. A month and a half after the installation, the auto_increment value is now at over 10 million. While there are a number of plugins installed (such as ACF and W3 Total Cache) they do not seem to be the cause. They have been installed on others sites together with the same theme framework without any issues. I have a local dev environment of …
Category: Web

WordPress Settings API, Implementing Tabs On Custom Menu Page

I've been following the WordPress Settings API tutorial series of this guy: http://wp.tutsplus.com/tutorials/theme-development/the-complete-guide-to-the-wordpress-settings-api-part-1/ So far, I've been successful at doing the basic thing. Now, when implementing tab, I'm facing problem. Problem 1: The Tabs are not working. All the fields are being displayed on both the tabs. Section 1, should be displayed on Tab One and Section 2 on Tab Two. Problem 2: Option 2 is not being saved. It was working fine before implementing tabs. Code: /* ----------------------------------------------------------------------------- */ …
Category: Web

update_option is not working!

I am writing a plugin and I need to use the update_option function to update an array I have stored as an option in WP. For the admin panel I used the settings API but for this portion I need to use the update_option directly. I have simplified my code so all it is currently doing is reading in the option, adding an element to the returned array, and updating the option with the modified array. But when I read …
Category: Web

Wordpress address URL keeps dropping the www

My Wordpress Address (URL) in general settings keeps losing the www from the URL - I type in http://www.domain.com and it saves and works fine. Next time I go in the address has changed to http://domain.com. So again I change it, I get logged out and I log back in and it looks fine until next time and it has changed again. This is the only setting which changes (site address keeps the www) and I have checked my htaccess …
Category: Web

Category URL to use same string as Post URL Permalink

I want to set up my site to have the following permalink structure: /learn/%category%/%postname% So in the permalinks section of wordpress, I set that as the custom structure. The issue is, when I click on a category page it's just: /%category%/ (it's ends up being a /category/subcategory/ url). So I tried setting the category base on the permalinks setting page also to /learn/, but then I get a 404 when I go to a post's page. How do I make …
Category: Web

Get category slug and display it on a query_post

I just read "How to create option page for wordpress theme" in wp.tutsplus.com - I have a problem with getting categories . there is two parts to my question - Part A - Get category slug and display it In this tutorial there is a select option as follow : $options[] = array( "section" => "select_section", "id" => WPTUTS_SHORTNAME . "_select_input", "title" => __( 'Select (type one)', 'wptuts_textdomain' ), "desc" => __( 'A regular select form field', 'wptuts_textdomain' ), "type" …
Category: Web

Huge wp_options table

I have a problem on a WP site. Website crashes because there is no more available disk space. Searching, i detect that wp_options table size is 12GB, but only have 1100 rows aprox: Any ideas? Thanks in advance [UPDATE 1] If i export wp_options table, drop and import, sizes reduces at 9,7mb: I had no opportunity to optimize the table with OPTIMIZE TABLE wp_options but I will try it if it happens again [UPDATE 2] Problem still here. I try …
Category: Web

Performance with autoload and the options table

I am playing around with the autoload column of the options table. I didn't find much information about how the autoloaded values are used. I tried a print_r($GLOBALS) and saw that the autoloaded options are stored in $GLOBALS['wp_object_cache']->cache['options']['alloptions']. Is there another way to access those variables? Suppose I need to access an option my_option, which was set to autoload, multiple times in different templates (eg. once in header.php, once in footer.php), which method is recommended? Is it okay that I …
Category: Web

How to get specific setting by settings_fields()?

I am working on a plugin and on the settings page I have 2 settings and I want to show Only one setting "backgroundColor" so how should i do that? This is the code: <form action="options.php" method="post"> <?php settings_errors(); settings_fields( 'bg_color' ); **<<< I want only background settings to show how i can do it correclty?** do_settings_sections( 'plugin-style' ); submit_button( __('Save settings', 'trans') ); ?> </form> /* Add Settings Field for Background Color */ add_settings_field( 'background-color', __('Background Color', 'trans'), 'plugin_background_color_ca', …
Category: Web

Same ACF Relationship field for multiple Post Options sub-pages?

How can I ensure that the data saved by an Advanced Custom Fields Relationship field, when on an Options page for a Post type, is separate? Detail below: I have an ACF field group, “Features”, containing a Relationship field. It is intended to allow me to pre-set some featured posts for a couple of custom post types – “Reports” and “Articles”. For those post types, in the same code that registers each post type, I have created an Options sub-page …
Category: Web

Check if an option exists and get its value in one hit

I have an option admins_settings that has an array of sub-options that is stored in the wp_options table. Before I get its value from the table, I check if this field exists by running this code: if ( !isset( get_option( 'admins_settings' )['option_name'] ) ) { return false; } else { return get_option( 'admins_settings' )['option_name']; } Here, I'm hitting the table 2 times (if the field exists) to get its value. Is there any way to get the value of the …
Category: Web

get_site_option / update_site_option - the main site and sub sites do not share the same storage

get_site_option / update_site_option is supposed to get / update an option for the current network (contrary to its name). I have noticed that it works only for sub-sites, all sub-sites share the same settings storage, however, the "main" site does not (the initial site that is not a subdomain or subdir). Why is that?
Category: Web

Wordpress Select Option Load Custom Fields

I created a new post type called "Programs" and i created custom fields on Programs width Advanced Custom Fields plugin. I want to compare the Programs fields with each other on the page width select option. Like this; I brought the program names to the select section. <div class="ud-program-check__table-header-item"> <?php $posts = get_posts (array ( 'numberposts' => -1, // -1 returns all posts 'post_type' => 'programs', 'orderby' => 'title', 'order' => 'ASC' )); ?> <select id="my_great_select" name="my_great_select"> <?php foreach ($posts …
Category: Web

Add Plugin options as subpage to Theme options page

I have my own Theme with an options page. Now I am developing a new Plugin which should have an options page that should be a subpage of the Theme options page. Theme options.php: <?php function xx_theme_admin_menu() { add_menu_page( 'Theme Settings', 'Theme Settings', 'manage_options', 'xx-settings', 'xx_theme_admin_page' , '/wp-content/themes/xx/assets/img/logo-Grayscale-30x25.png' ); } add_action( 'admin_menu', 'xx_theme_admin_menu' ); function xx_theme_admin_page() { ... } Plugin options.php: <?php function xx_cookie_banner_admin_menu() { add_submenu_page( 'xx-settings', 'Cookie Banner', 'Cookie Banner', 'manage_options', 'xx-cookie-banner', 'xx_cookie_banner_admin_page' ); } add_action( 'admin_menu', 'xx_cookie_banner_admin_menu' ); …
Category: Web

get_option() not returning expected value from plugin

I am trying to make my first plugin, and so far everything has been fine except one little annoying thing. I have my fields setup and updating data and looks just fine in my database: mfwp_settings | a:1:{i:test;s:3:"response";} But when I want to echo the value for 'test' in my Admin Panel it comes back blank or NULL. It echos fine on a front end page but within the the plugin it wont retrieve the data using the following: $mfwp_opt …
Category: Web

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.