Get post title by Alphabet

You have two problems. First need to global $wpdb;. Then you are using the_title() and the_permalink() both of which automatically echo out a value. So you need to switch them to get_the_title() and get_permalink(). function get_post_by_alphabet($the_char){ global $wpdb; $first_char = $the_char; $postids=$wpdb->get_col($wpdb->prepare(” SELECT ID FROM $wpdb->posts WHERE SUBSTR($wpdb->posts.post_title,1,1) = %s ORDER BY $wpdb->posts.post_title”,$first_char)); if ($postids) … Read more

wpdb select from using array as search parameters

Pass your information through prepare as in this example from the Codex: $metakey = “Harriet’s Adages”; $metavalue = “WordPress’ database interface is like Sunday Morning: Easy.”; $wpdb->query( $wpdb->prepare( ” INSERT INTO $wpdb->postmeta ( post_id, meta_key, meta_value ) VALUES ( %d, %s, %s ) “, array( 10, $metakey, $metavalue ) ) ); Your array should have … Read more

Widget & storing a Select box choice

Here’s the working answer for future reference. <p> <label for=”<?php echo $this->get_field_id(‘select’); ?>”><?php _e(‘Choose A Page:’, ‘check_avail_widget’); ?></label> <select name=”<?php echo $this->get_field_name(‘select’); ?>” id=”<?php echo $this->get_field_id(‘select’); ?>” class=”widefat”> <option value=”Select A Page”> <?php echo esc_attr( __(‘Select A Page’) ); ?> </option> <?php $pages = get_pages(); foreach ($pages as $page) { echo ‘<option value=”‘.get_page_link($page->ID).'” id=”‘ . … Read more

Selecting NULL value from the database

There is no specific issue with retrieving null values from the database. They will come back as the PHP NULL value. WordPress uses either the function mysqli_fetch_object or mysql_fetch_object to retrieve results from the database. https://php.net/manual/en/function.mysql-fetch-object.php https://php.net/manual/en/mysqli-result.fetch-object.php According to those respective pages: Note: This function sets NULL fields to the PHP NULL value. Are you … Read more

Add category selection to function request

Instead of a sql query, I recommend to do it in wordpress way: $args = array( ‘numberposts’ => 3, ‘offset’ => 0, ‘category’ => put_your_category_id_here, ‘orderby’ => ‘post_date’, ‘order’ => ‘DESC’, ‘post_type’ => ‘post’, ‘post_status’ => ‘publish’, ‘suppress_filters’ => true ); $request = wp_get_recent_posts( $args, ARRAY_A ); Reference : WordPress Update : here is the … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)