Create a post automatically if search result has zero results

Assuming you are using the standard WordPress search, you can get the searched number with get_search_query So this code will create a new draft post if no results were found for the search: $match = get_page_by_title( sanitize_title( get_search_query() ), OBJECT, [‘post_type’ => ‘post’] ); if ( empty( $match ) ) { wp_insert_post( [‘post_title’ => sanitize_title( … Read more

Help with query_posts function

The query_posts() function is almost wholly unnecessary and is discouraged in favor of WP_Query(). That being said we can look at the WP_Query() docs as they’re almost the same. The cat parameter accepts either a comma separated string or integer. In this case we can use: query_posts( array( ‘cat’ => 1, ‘posts_per_page’ => ‘8’, ‘post__not_in’ … Read more

WordPress sorting posts by date and title using a dropdown

Here I put orderby attributes as option values – date and title. <form method=”GET”> <select name=”orderby” id=”orderby”> <option value=”date”>Newest to Oldest</option> <option value=”title”>Alphabetical</option> <button type=”submit”>Apply</button> <form> On the same page you can recieve select value and set as orderby attribute $wpb_all_query = new WP_Query(array( ‘post_type’=>’post’, ‘posts_per_page’=>-1, ‘order’=>’ASC’, ‘orderby’=> esc_attr($_GET[‘orderby’]) ); Use your loop to show … Read more

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