Skip to main content
added a possible alternative, but not definitive, solution
Source Link
user47133
user47133

In the "form" method of one of my widgets I make a query to offer the user some posts to choose from, like this:

<?php
    $products = new WP_Query( array(
        'post_type'      => 'ys_product',
        'order'          => 'ASC',
        'orderby'        => 'title',
        'meta_query'     => array(
            array(
                'key'   => 'ys_product_status',
                'value' => 'ok',
            )
        ),
        'posts_per_page' => - 1
    ) );
    
    
    if ( $products->have_posts() ) {
        while ( $products->have_posts() ) : $products->the_post();
            $product = array(
                'name' => the_title_attribute( array( 'echo' => FALSE ) ),
                'ID'   => get_the_ID(),
            );
    
            $prod_array[] = $product;
        endwhile;
        wp_reset_postdata();
    }

For some reason, with that code there things go more or less wrong. The widget works, the wp_query populates the appropriate select, the widget displays and can be configured both through regular the Widgets page or the Customizer.

But...

For some reason, while in the customizer this widget has the following css rule applied:

.customize-control-widget_form:not(.widget-rendered) {
  opacity. 0.5
}

Which of course in turn produces this: widget with opacity changed

Also, while in the customizer I can't use anymore the "add new widget" button unless I remove this widget (it gives an error in customizer.js, complaining that TypeError: control is undefined.

Everything seems to work, but obviously something is wrong because I'm breaking Customizer. Anyone has a clue what's going on here?

Update: I ended up replacing WP_Query with a an sql query through $wpdb, and now everything works as intended. Still, would like to know why it isn't working as it should written as it was. :(

Thanks and regards. (WP 4.1)

In the "form" method of one of my widgets I make a query to offer the user some posts to choose from, like this:

<?php
    $products = new WP_Query( array(
        'post_type'      => 'ys_product',
        'order'          => 'ASC',
        'orderby'        => 'title',
        'meta_query'     => array(
            array(
                'key'   => 'ys_product_status',
                'value' => 'ok',
            )
        ),
        'posts_per_page' => - 1
    ) );
    
    
    if ( $products->have_posts() ) {
        while ( $products->have_posts() ) : $products->the_post();
            $product = array(
                'name' => the_title_attribute( array( 'echo' => FALSE ) ),
                'ID'   => get_the_ID(),
            );
    
            $prod_array[] = $product;
        endwhile;
        wp_reset_postdata();
    }

For some reason, with that code there things go more or less wrong. The widget works, the wp_query populates the appropriate select, the widget displays and can be configured both through regular the Widgets page or the Customizer.

But...

For some reason, while in the customizer this widget has the following css rule applied:

.customize-control-widget_form:not(.widget-rendered) {
  opacity. 0.5
}

Which of course in turn produces this: widget with opacity changed

Also, while in the customizer I can't use anymore the "add new widget" button unless I remove this widget (it gives an error in customizer.js, complaining that TypeError: control is undefined.

Everything seems to work, but obviously something is wrong because I'm breaking Customizer. Anyone has a clue what's going on here?

Thanks and regards. (WP 4.1)

In the "form" method of one of my widgets I make a query to offer the user some posts to choose from, like this:

<?php
    $products = new WP_Query( array(
        'post_type'      => 'ys_product',
        'order'          => 'ASC',
        'orderby'        => 'title',
        'meta_query'     => array(
            array(
                'key'   => 'ys_product_status',
                'value' => 'ok',
            )
        ),
        'posts_per_page' => - 1
    ) );
    
    
    if ( $products->have_posts() ) {
        while ( $products->have_posts() ) : $products->the_post();
            $product = array(
                'name' => the_title_attribute( array( 'echo' => FALSE ) ),
                'ID'   => get_the_ID(),
            );
    
            $prod_array[] = $product;
        endwhile;
        wp_reset_postdata();
    }

For some reason, with that code there things go more or less wrong. The widget works, the wp_query populates the appropriate select, the widget displays and can be configured both through regular the Widgets page or the Customizer.

But...

For some reason, while in the customizer this widget has the following css rule applied:

.customize-control-widget_form:not(.widget-rendered) {
  opacity. 0.5
}

Which of course in turn produces this: widget with opacity changed

Also, while in the customizer I can't use anymore the "add new widget" button unless I remove this widget (it gives an error in customizer.js, complaining that TypeError: control is undefined.

Everything seems to work, but obviously something is wrong because I'm breaking Customizer. Anyone has a clue what's going on here?

Update: I ended up replacing WP_Query with a an sql query through $wpdb, and now everything works as intended. Still, would like to know why it isn't working as it should written as it was. :(

Thanks and regards. (WP 4.1)

changed the nature of the question, added detail
Source Link
user47133
user47133

.customize-control-widget_form:not(.widget-rendered) class applied to widget wp_query in form method of widget breaks customizer

In the "form" method of one of my widgets I make a query to offer the user some posts to choose from, like this:

<?php
    $products = new WP_Query( array(
        'post_type'      => 'ys_product',
        'order'          => 'ASC',
        'orderby'        => 'title',
        'meta_query'     => array(
            array(
                'key'   => 'ys_product_status',
                'value' => 'ok',
            )
        ),
        'posts_per_page' => - 1
    ) );
    
    
    if ( $products->have_posts() ) {
        while ( $products->have_posts() ) : $products->the_post();
            $product = array(
                'name' => the_title_attribute( array( 'echo' => FALSE ) ),
                'ID'   => get_the_ID(),
            );
    
            $prod_array[] = $product;
        endwhile;
        wp_reset_postdata();
    }

For some reason, with that code there things go more or less wrong. The widget works, the wp_query populates the appropriate select, the widget displays and can be configured both through regular the Widgets page or the Customizer.

But...

For some reason, while in the customizer one of my widgetsthis widget has the following css rule applied:

.customize-control-widget_form:not(.widget-rendered) {
  opacity. 0.5
}

Which of course in turn produces this: widget with opacity changed

I understand the ruleAlso, but not why WP is applying said rule to my Widget. On what situations does Wordpress do that? What I have left out? In the regular Widgets pagewhile in the Dashboard it's show normally, and as far ascustomizer I can seecan't use anymore the "add new widget" button unless I remove this widget is functionning(it gives an error in customizer. Stilljs, the opacity changecomplaining that TypeError: control is undefined.

Everything seems to work, but obviously something is bothering us a bitwrong because I'm breaking Customizer. Anyone has a clue what's going on here?

Thanks and regards. (WP 4.1)

.customize-control-widget_form:not(.widget-rendered) class applied to widget in customizer

For some reason, while in the customizer one of my widgets has the following css rule applied:

.customize-control-widget_form:not(.widget-rendered) {
  opacity. 0.5
}

Which of course in turn produces this: widget with opacity changed

I understand the rule, but not why WP is applying said rule to my Widget. On what situations does Wordpress do that? What I have left out? In the regular Widgets page in the Dashboard it's show normally, and as far as I can see the widget is functionning. Still, the opacity change is bothering us a bit.

Thanks and regards. (WP 4.1)

wp_query in form method of widget breaks customizer

In the "form" method of one of my widgets I make a query to offer the user some posts to choose from, like this:

<?php
    $products = new WP_Query( array(
        'post_type'      => 'ys_product',
        'order'          => 'ASC',
        'orderby'        => 'title',
        'meta_query'     => array(
            array(
                'key'   => 'ys_product_status',
                'value' => 'ok',
            )
        ),
        'posts_per_page' => - 1
    ) );
    
    
    if ( $products->have_posts() ) {
        while ( $products->have_posts() ) : $products->the_post();
            $product = array(
                'name' => the_title_attribute( array( 'echo' => FALSE ) ),
                'ID'   => get_the_ID(),
            );
    
            $prod_array[] = $product;
        endwhile;
        wp_reset_postdata();
    }

For some reason, with that code there things go more or less wrong. The widget works, the wp_query populates the appropriate select, the widget displays and can be configured both through regular the Widgets page or the Customizer.

But...

For some reason, while in the customizer this widget has the following css rule applied:

.customize-control-widget_form:not(.widget-rendered) {
  opacity. 0.5
}

Which of course in turn produces this: widget with opacity changed

Also, while in the customizer I can't use anymore the "add new widget" button unless I remove this widget (it gives an error in customizer.js, complaining that TypeError: control is undefined.

Everything seems to work, but obviously something is wrong because I'm breaking Customizer. Anyone has a clue what's going on here?

Thanks and regards. (WP 4.1)

Source Link
user47133
user47133

.customize-control-widget_form:not(.widget-rendered) class applied to widget in customizer

For some reason, while in the customizer one of my widgets has the following css rule applied:

.customize-control-widget_form:not(.widget-rendered) {
  opacity. 0.5
}

Which of course in turn produces this: widget with opacity changed

I understand the rule, but not why WP is applying said rule to my Widget. On what situations does Wordpress do that? What I have left out? In the regular Widgets page in the Dashboard it's show normally, and as far as I can see the widget is functionning. Still, the opacity change is bothering us a bit.

Thanks and regards. (WP 4.1)