• Resolved heinyken

    (@heinyken)


    Greetings! I’ve got a stickler of a problem for everyone today.

    I searched for how to register sidebars so that I could create dynamic sidebars on particular pages. This is the code I’ve used to do so:

    (in functions.php)

    if ( function_exists('register_sidebar') ) {
    	register_sidebar(array(
    		'name' => 'Testimonials',
    		'id' => '1',
    		'before_widget' => '',
    		'after_widget' => '',
    		'before_title' => '<h4>',
    		'after_title' => '</h4>',
    	));

    (in sidebar.php)

    if ( is_page(38)) {
    dynamic_sidebar('Testimonials');
    }

    This has worked fine. The problem occurs when I place a text widget into that sidebar in the Appearance->Widgets section. The text widget goes into the sidebar, gets edited, gets saved and then shows up on the webpage as it is meant to (this is not the problem, 🙂 ).

    After this, if I go to Appearance->Widgets, all the text boxes within the widgets disappear. It seems that the data for the widgets is not being retrieved from the database, even though it’s being used on the page properly. Following this, the database data is then overwritten with the blank widgets, thus losing the text widget.

    The problem is not what’s being put into the text widgets – I put “I hope this deletes” into a text widget and it was not retrieved once I edited the widgets in Appearance->Widgets. The problem is that data is not being retrieved and displayed on the Widgets page. Any help?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Maybe the problem lies with the ID, try changing the ID line to read..

    'id' => 'sidebar-$i',

    Or remove the ID line altogether and let WordPress assign one.

    Not sure that will help at all, but it’s a suggestion nonetheless… 😉

    Thread Starter heinyken

    (@heinyken)

    Thank you very much, Mark, you put me on the right path. That half-worked, and through process of elimination, got to the bottom of it all: apparently the API for naming an ID requires that it’s a string and that it starts with a letter. So you were right: naming it that helped, however we had to put it inside double quotes for it to work.
    It now looks like this:

    if ( function_exists('register_sidebar') ) {
    	register_sidebar(array(
    		'name' => 'testimonials',
    		'id' => "sidebar-1",
    		'before_widget' => '',
    		'after_widget' => '',
    		'before_title' => '<h4>',
    		'after_title' => '</h4>',
    	));
    	register_sidebar(array(
    		'name' => 'Customers Hunting',
    		'id' => "sidebar-2",
    		'before_widget' => '',
    		'after_widget' => '',
    		'before_title' => '<h4>',
    		'after_title' => '</h4>',
    	));

    And works like a charm. So it seems the answer is to have it inside double quotes and to start with a letter.

    Thanks a lot Mark, this was scary and VERY annoying, haha, I’m glad to have it worked out. Sure hope it helps someone else in the future.

    Oh yes my mistake, variables are treated as literal in a single quote string, silly mistake on my part (i should know better, lol).

    Happy to hear you got your problem all worked out though.. 😉

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Text widget data not being retrieved upon Edit’ is closed to new replies.