#StackBounty: #theme-development #page-template Loop inside page template not working

Bounty: 50

I am facing a problem with the loop inside the page template. Here is the code.

<?php
/* Template Name: Blog-Template */

get_header();

$args = [
 'post_type' => 'post',
 'posts_per_page' => 1,
];

$queryP = new WP_Query( $args );

if ($queryP->have_posts()) {
    while ( $queryP->have_posts() ) : $queryP->the_post();
        ?>
        <article>
            <?php

            the_title( '<h1>', '</h1>' );
            the_excerpt();

            ?>
        </article>
        <?php
    endwhile;
}

get_footer();

If I set this page as a blog page in settings then no problem happens. But when I create a custom loop for this template it doesn’t work. It shows nothing just header and footer.


Get this bounty!!!

#StackBounty: #customization #theme-development #taxonomy #theme-customizer wordpress customizer – pass setting value into another cont…

Bounty: 50

In the wordpress customizer script I am trying to pass the value from a select control into a custom control that displays taxonomies associated with the selected value (1st control). –

                $wp_customize->add_control( new Tax_Dropdown_Control( $wp_customize, 'select_tax', array(
                        'section'       => 'section_1',
                        'label'         => __( 'Select Post Taxonomy', 'textdomain' ),
                        'description'   => __( 'Select a taxonomy based on post type selected.', 'textdomain' ),
                        'dropdown_args' => array(
                            'post_type' => $wp_customize->get_setting("select_post_type"), // here I need to pass the first setting's value
                        ),
                    ) ) );
            
             // custom controls related snippet
    class Tax_Dropdown_Control extends WP_Customize_Control {
        .....    
        $dropdown_args = wp_parse_args( $this->dropdown_args, array(
                        'post_type'          => 'post',
                    ) );
            
                    $dropdown_args['echo'] = false;
                    
                    $taxonomies = get_object_taxonomies($dropdown_args);
                    
            if  ($taxonomies) {
            echo '<select>';
              foreach ($taxonomies  as $taxonomy ) {
                echo '<option>'. $taxonomy. '</option>';
              }
              echo '</select>';
            } 
        ....
}

It would need to update the choices live when the select post type is changed. I’m not sure if maybe an active_callback can be used to recall the function with the updated variable?


Get this bounty!!!

#StackBounty: #plugin-development #theme-development #custom-field #metabox #options Best choice of options/settings framework for plug…

Bounty: 50

My question is what is the best options/settings framework out there now to safely build custom plugin/theme upon? I found the similar question here, but it was asked 7 years ago and definitely, things changed from that time.

I used ACF a lot to manage custom meta fields and creating theme options page. The plugin is great, but the main drawbacks for me are: difficult to translate (clone/repeater field bugs with WPML, manual field translation settings for EVERY field), hard to figure out compatibility issues if included with plugin (what if ACF is already used in theme, what if it’s free version or older PRO version then included etc.)

I also used GenerateWP and https://www.wp-hasty.com/ for settings page options that leverage native WP Settings API and are the best, in my opinion, to not overcomplicate things, but it’s often that I need more advanced fields (map, repeater etc.)

I investigated Meta Box, CMB2, Redux, Options Tree and Titan Framework and can’t decide what is the best to use to include in the plugin/theme. I liked the Redux design fields and also the fact that Titan Framework is called as a class instance (less compatibility issues with other plugins?). The online Meta Box generator is also a cool thing.

So the question is, what is the best framework you like to use/tried?

Thank you and happy coding 🙂


Get this bounty!!!

#StackBounty: #theme-development #themes #translation Some translations do not work in my template class

Bounty: 50

I am struggling with the translations of my theme. I use the function get_permalink_date of my class. The relevant snippet is:

$permalink_title = sprintf(
    /* translators: 1 = Post Title, 2 = Author Name */
    esc_html_x( '%1$s by %2$s', 'permalink title', 'themeberger' ),
    __( 'A post', 'themeberger' ),
    get_the_author_meta( 'display_name', $this->post->post_author )
);

What I don’t understand is that the translation from __(); works, but esc_html_x(); does not. I hope that someone can help me.

The relevant part from the .po file is:

#. translators: %1$s: Post Title. %2$s: Author Name.
#: themeberger/class-themeberger-post-functions.php:237
msgid "%1$s by %2$s"
msgstr "%1$s von %2$s"

#: themeberger/class-themeberger-post-functions.php:238
msgid "A post"
msgstr "Ein Beitrag"

The output is <a href="[...]" title="Ein Beitrag by Christian Hockenberger">[...]</a>

I really don’t get it. In another line also _x( '%s ago', '%s = human-readable time difference', 'themeberger' ) is not working. I first thought that for some reason the translations are not transferred to the class, but __(); works.

What can I do?


Get this bounty!!!

#StackBounty: #theme-development #themes Retrieve data using wpdb to use for customizer controls

Bounty: 50

So I have the following code:

add_action('customize_register', 'homepage_sections');
//products
function homepage_sections($wp_customize){
    $wp_customize->add_panel('homepage_sections', array(
        'title'             => 'Homepage Sections',
        'priority'          => '20'
    ));
    $wp_customize->add_section('homepage_settings_section', array(
        'title'             =>  'Homepage settings',
        'panel'             =>  'homepage_sections',
    ));
    $wp_customize->add_setting('homepage_settings_setting', array(
        'default'           =>  1
    ));
    $wp_customize->add_control('homepage_settings_control', array(
        'section'           =>  'homepage_settings_section',
        'settings'          =>  'homepage_settings_setting',
        'label'             =>  'Number of sections',
        'description'       =>  'Number of sections in homepage',
        'type'              =>  'number'
    ));


    global $wpdb;
    $sections=$wpdb->get_results('SELECT section_id, section_title FROM vt_homepage_sections;');

    foreach($sections as $key){
        $section_id=$key->section_id;
        $cust_setting_id=$section_id.'_setting';
        $cust_control_id=$section_id.'_control';


        $wp_customize->add_setting($cust_setting_id,array(

        ));
        $wp_customize->add_control($cust_control_id,array(
            'settings'          =>  $cust_setting_id,
            'section'           =>  'homepage_settings_section',
            'label'             =>  'test Control'
        ));
    }
}

Issue
Everything works fine when i don’t use variables which contain a value fetched using $wpdb. Is $wpdb object loaded after customizer framework?

When I use the code above, the above customized objects font appear in the customizer panel. Would appreciate hints to what’s wrong with my code above.

regards,

J


Get this bounty!!!

#StackBounty: #theme-development #upgrade Upgrade from 5.0.4 to 5.1.1 causes $theme to be null

Bounty: 50

When we upgrade from 5.0.4 to 5.1.1 the site stops loading.

The error message is

Fatal error:  Uncaught Error: Call to a member function images_path() on null 
/wp-content/themes/mytheme/header.php on line 49

Line 49 is
<?php $theme->images_path(); ?>

$theme is created in functions.php as the instance of our custom theme.

class MyTheme {
...
}

$theme = new MyTheme();

The full stacktrace is

Stack trace:
/wp-includes/template.php(704): require_once()
/wp-includes/template.php(653): load_template('/nas/content/li...', true)
/wp-includes/general-template.php(41): locate_template(Array, true)
/wp-content/themes/myTheme/page-home.php(7): get_header()
/wp-includes/template-loader.php(77): include('/nas/content/li...')
/wp-blog-header.php(19): require_once('/nas/content/li...')
/index.php(17): require('/nas/content/li...')n#7 {main}

thrown in 
/wp-content/themes/myTheme/header.php on line 49

I don’t know how to troubleshoot this issue. Everything worked great prior to the upgrade and no other changes were made to the site.

Any help appreciated.


Get this bounty!!!