!in_array doesnt recognize category

Try it like this: if ( $query->have_posts() ) { $categories = $category_ids = array(); while ( $query->have_posts() ) { $query->the_post(); foreach ( ( get_the_category() ) as $category ) { if ( ! in_array( $category->term_id, $category_ids ) ) { $category_ids[] = $category->term_id; $categories[] = $category; } } }; } get_the_category() returns an array of objects. I … Read more

Sort Posts Alphabetically by Multiple Categories [duplicate]

Use the orderby and order parameters in the argument list. See the Orderby_Parameters section of WP_Query for details. $category_ids = $arr_records = $post_data = array(); $categories = get_categories( ‘child_of=4’ ); foreach( $categories as $category ) { $category_ids[] = $category->term_id; } $post_data = get_posts( array( ‘cat’ => $category_ids, ‘orderby’ => ‘title’, ‘order’ => ‘ASC’, ) ); … Read more

wpdb Cannot Access Associative Array Data in a Count Query

You can simplify that by using $wpdb->get_var. $total = $wpdb->get_var( “SELECT COUNT( * ) AS total FROM tableA” ); echo “Total Records:” . $total; However, the code you’ve got should work– either version of it. I tested both. The only thing I notice is that the first version of the code should give you Array … Read more

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