0

get_theme_mod is returning cached content: this code:

$parallax_one_logos = get_theme_mod('parallax_one_logos_content',
    json_encode(
        array(
            array("image_url" => parallax_get_file('/images/companies/1.png') ,"link" => "#" ),
            array("image_url" => parallax_get_file('/images/companies/2.png') ,"link" => "#" ))
    )
);

And this code, containing a bollocks test value.

get_theme_mod('parallax_one_logos_content', 
    json_encode('test'))

Return the same value.
I have:

  1. Shut Down Apache
  2. Shut Down MySql
  3. Tried Ctrl-F5

I am at a loss as to how to remove / clear the cache that get_theme_mod uses.
If it helps I am using XAMPP on windows 10.

Thanks

  • If the theme mod option has a value in database, your code may be working just fine as it should return the value in database and ignore the second parameter. So, which value are you getting? Is it the value of the theme mod option in the database? – cybmeta Mar 30 '16 at 8:40
  • how do I clear all the values cached in the database, and return the newly calculated values. I want the cache completely cleared. I have renamed the project directory. – Jim Mar 30 '16 at 8:51
  • You should add that information to the question itsefl. – cybmeta Mar 30 '16 at 8:58
0

If the theme mod option has a value in database, your code is working just fine as it should return the value in database and ignore the second parameter. The second parameter is the default value to be used if there is no value is set. And the value is stored in database.

The problem is that you are wrong considering that the values of the theme mod are cached in database, they are stored in database, not cached; the query to get them from database can be cached but if you need to update the value of a theme mod, you have to update the value already stored in database. You can do it using set_theme_mod():

set_theme_mod( 'parallax_one_logos_content', 'new value' );
  • This doesn't seem to make any sense. Why have the values supplied to get_theme_mod then? there is absolutely no point to the second parameter to get_theme_mod if it's never used under any circumstances. I would rather remove all the values, and have get_theme_mod return the second parameter, otherwise it's clearly incorrect code, and get_theme_mod is incorrectly specified. – Jim Mar 30 '16 at 9:09
  • The second parameter is the default value to be used if no value has been set. Default values are really great to reduce database entries for default configuration settings because you don't need to store them in database, only custom values should be stored in database. It is not incorrect and it is clearly specified. It's you who are not understanding it well. Anyway, you can store default values in database if you wish using set_theme_mod() with those values. – cybmeta Mar 30 '16 at 10:24
-1

You can execute this command in mysql / workbench / phpAdmin etc to remove all the stored mod data from the database.

SET SQL_SAFE_UPDATES=0;
delete from wp_options where option_name like '%theme_mod%'

Regards
Craig.

  • that will probably delete settings of all themes, not just a specific one.... – Mark Kaplun Mar 30 '16 at 9:45
  • yes, true, and in my case the theme will not ever replace those values, so I will always evalulate the function, and never cache the values. This is a pity. There is a do action do_action('shutdown', 'parallax_one_add_id') that seems to set all the values, but I am not sure under what circumstances it is called. This horror all started when I renamed the project sub directory. – Jim Mar 30 '16 at 9:49
  • @cybmeta, your answer is actually correct, though the code would read and work way better if get_theme_mod stored the defaults in the database when they don't exist. It's broken in my option. – Jim Mar 30 '16 at 9:51
  • why would you want to cache any value in the DB if you can avoid it? Anyway, this is the wordpress pattern in regard to all options - It is really up to you to populate settings before they are being used.if you want them in the DB. – Mark Kaplun Mar 30 '16 at 10:10
  • dont' know why the down vote, it works perfectly well at removing the values, which was exactly my original question. I came very close to marking this is the correct answer. – Jim Mar 31 '16 at 4:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.