post loop with different design depending on post

Your $count++ needs to be after your endif statement. It’s not counting up because your counter is always at 0 which means you’re always in your “if” portion of your statement not your “else”. Like this: $args = array( ‘post_type’ => ‘post’, ‘post_per_page’ => 3, ); <?php $loop = new WP_Query($args); $count = 0; while … Read more

wp_logout action hook is not firing

In your code, get_current_user_id() will return 0 because this hook fires after the logout has happened, ie, there is no current user ID. If you want the $user_id to be available to your function, you have to pass it in. Note: the $user_id parameter was added in WordPress 5.5.0. If you’re using an older version, … Read more

How to use wp-query to search for posts where post_content OR post_title OR post_name

In WordPress 6.2+, within WP_Query you can set search_columns parameter (not documented at time of writing) to specify the fields to search: $query = new WP_Query( array( ‘s’ => ‘search term’, ‘search_columns’ => array( ‘post_content’, ‘post_name’, ‘post_title’ ), ) ); You can also use the post_search_columns filter to adjust the search columns. You may need … Read more

How to make OR condition in WP_Query

WP_Query does not handle this sort of query: use two instances of WP_Query, and then combine the results. Untested code: $posts = new WP_Query( array( ‘post_type’ => ‘post’, ) ); $post_ids = array_column( $posts->posts, ‘ID’ ); $author = new WP_Query( array( ‘post_type’ => ‘any’, ‘author’ => 123, ‘post__not_in’ => $post_ids, // prevent duplicates ) ); … Read more

new WP_Query with order args – no more distinction between categories

On the template driving your archive page, you can use the query_posts() function to adjust the main query (WordPress’ default main query, not your custom one). query_posts( array( ‘orderby’ => ‘modified’, ‘order’ => ‘ASC’, ) ); Using the pre_get_posts action is the better method, though slightly more complex (untested, would go in theme’s functions.php or … Read more

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