Forum Replies Created

Viewing 15 replies - 211 through 225 (of 247 total)
  • I would recommend using a Multisite installation instead or if you insist of only having a single wp instance go with a commercial plugin like WPML.

    WPML helps you keeping track when you want every page in every language you’re offering. If you want to localize your site, meaning potentially having different or more targeted content for different countries/languages as well Multisite is the way to go.

    Inside your shortcode handling function or method (https://codex.www.ads-software.com/Shortcode_API) you would have to create a custom WP_Query object (https://codex.www.ads-software.com/Class_Reference/WP_Query) like this

    function myCustomShortcodeHandler( $atts ){
    
      $CustomQuery  = new WP_Query( array( 'post__in' => array( 1, 2, 3 ) ) ); // Insert YOUR post IDs here
    
      wp_reset_query();
    
      foreach( $CustomQuery->posts as $Post ) {
    
        /**
         * $Post->ID
         * $Post->post_title
         * $Post->post_excerpt
         * $Post->post_content
         * ...
         */
      }
    
      return;
    
    }
    
    add_shortcode( 'myCustomShortcode', 'myCustomShortcodeHandler' );
    Forum: Hacks
    In reply to: Radio Buttons in Widget

    The form() method:
    The HTML “id” attribute has to be unique in order to form a valid DOM element. This can be achieved by simply adding a -{nr}
    The “for” attribute of each(!) <label> element refers to that id. Though this would be the correct way, having a proper id and for attribute will only matter for DOM operations, not for saving the widget data itself.

    The “value” attribute of each radio element also has to be unique, otherwise you cannot save “different” ratings/values.

    public function form( $instance ) {
    
        echo "    <p>\n";
        echo "     <legend>Rating:</legend>\n";
    
        // 0 being the default value or "no rating set (yet)"
        $rating = ( isset( $instance['rating'] ) && is_numeric( $instance['rating'] ) ) ? (int) $instance['rating'] : 0;
    
        for( $n = 1; $n < 6; $n++ ) {
    
          echo '     <input type="radio" id="' . $this->get_field_id( 'rating' ) . '-' . $n . '" name="' . $this->get_field_name( 'rating' ) . '" value="' . $n . '" ' . checked( $rating == $n, true, false ) . '><label for="' . $this->get_field_id( 'rating' ) . '-' . $n . '"> ' . $n . '</label><br />' . "\n";
    
        }
    
        echo "    </p>\n";
    
      }

    The update() method:
    Basically that’ll do but the idea is to properly validate the data before saving it. And since you know your value should be numerical and more specific, between 1-5 (or in my example 0 and 5) you could explicitly test for that rule.

    public function update( $new_instance, $old_instance ) {
    
        $instance = array();
    
        $instance['rating'] = ( isset( $new_instance['rating'] ) && $new_instance['rating'] > 0 && $new_instance['rating'] < 6 ) ? (int) $new_instance['rating'] : 0;
    
      return $instance;
    
      }

    Just recognized: Have you tried WHERE user_email instead of WHERE user_login in your SQL query?

    You can get a custom user object without having to query the DB by yourself like this:
    $User = get_user_by( 'email', $user_login_email );
    $User->ID would then give you the ID, for example.

    You could do a proper auto-redirect on your homepage:

    $categoryLink  = get_category_link( $categoryID );
    wp_redirect( $categoryLink, 301 );
    exit;

    I don’t mean to spam but actually my code from above was wrong^^, sry. It would have to be
    if( !key_exists( 'myNewShortCode', $shortcode_tag ) ) {...

    I was a bit slower than Michael ?? But he’s right: Prefixing should always be the way to go.

    Shortcodes are being stored in a global variable/array. So you could do something like this:

    global $shortcode_tag;
    if( !in_array( 'myNewShortcode', $shortcode_tag ) ) {
    ...add myNewShortcode...
    }

    For a case insensitive check you would have to aim for the “slug” which is also stored in $shortcode_tag

    Forum: Hacks
    In reply to: Settings in plugin.

    Loueen was talking about plugins, not widgets in particular. And since you can specify if an option shall be loaded automatically or manually I think the option functions are just fine.

    Forum: Hacks
    In reply to: Settings in plugin.

    wp_options, respectively all functions like add_option(), delete_option(), update_option(), etc are suited also for plugin settings.

    I would also recommend organizing all settings for a plugin in a single array and only store this one in the wp options. This way you will get all settings with only one query, even when using get_option();
    And it’s also easier to keep track of it when you want to uninstall the plugin and therefore delete the settings.

    Forum: Hacks
    In reply to: Explain these DB values

    You’re looking at serialized strings of data. You can unserialize them with PHP and take a look at them in a human readable form, so to speak. But the string you’re transforming has to be complete (with all the “etc etc” stuff)

    $unserializedData = ( unserialize( $theStringYourTalkingAbout );
    var_dump( $$unserializedData );

    The function wp_list_categories is declared in wp-includes\category-template.php You could also copy the old function from your 3.4.2 installation, rename it to, say, wp_list_categories_old, then call this instead of wp_categories in your code and see if that’s returning the proper list.

    So the next variable to check would be var_dump( $this_category->cat_ID ); Does it show a proper ID?
    You can cross check manually in the admin backend under posts/categories and hover over the category names. The links would contain something like &tag_ID={category_id}

    If $this_category->cat_ID does show an existing ID you could also use get_categories() as an alternative to wp_list_categories which then will/should return an array instead of an HTML formatted list.

    $kitten = get_categories(
      array(
        'type'      => 'post',
        'child_of'  => $this_category->cat_ID,
        'orderby'   => 'id',
        'order'     => 'ASC',
        'taxonomy'  => 'category'
      )
    );

    Other than that I’m out of ideas (for now), sry.

    Upfront, the function get_category_children() is marked “depricated since WP 2.8”. Though even if it seems to be working you can’t rely on that.
    Assuming $this_category->cat_ID is containing a valid ID you could do this:

    $kitten = wp_list_categories(
      array(
        'orderby'             => 'id',
        'show_count'          => 0,
        'use_desc_for_title'  => 1,
        'child_of'            => $this_category->cat_ID,
        'echo'  	            => 0
      )
    );
    
    if( !preg_match( '#no categories#i', $kitten ) ) {
    
      echo "<div class='ab-subcats' >";
    	echo ' <h3 class="title"></h3>';
      echo "<ul>";
      echo $kitten;
      echo "</ul> ";
    	echo "</div>";
    
    }

    If that’s still not showing anything you could also add var_dump( $kitten ); and check (and maybe post) what wp_list_categories() is returning.

Viewing 15 replies - 211 through 225 (of 247 total)