How can I limit the length of the previous/next posts in my WordPress Theme?

Here’s a little coding that should implement this for you: <?php $max_length = 5; // set max character length here $next = get_next_post()->ID; $prev = get_previous_post()->ID; if( $prev ) { $title = get_the_title( $prev ); $link = get_the_permalink( $prev ); $post_name = mb_strlen( $title ) > $max_length ? mb_substr( $title, 0, $max_length ) . ‘ … Read more

How to exclude pages from the search results

Note that when we use: $query->set( ‘post_type’, ‘post’ ); then we’re overriding all searchable post types, not only the page post type. That may be just fine in some cases, and we’re done using some of your pre_get_posts snippets that fit our needs. But sometimes we don’t want to hard fix it that way. Here … Read more

Custom SQL query to get List of posts with featured image url

Worked on similar problem recently. Here is the SQL query to get the post with Featured Image. global $wpdb; $perpage = 10; $page = 1; // Get the current page FROM $wp_query $counter = $perpage * $page; $uploadDir = wp_upload_dir(); $uploadDir = $uploadDir[‘baseurl’]; $sql = ” SELECT post.ID, post.post_title, post.post_date, post.category_name, post.category_slug, post.category_id, CONCAT( ‘”.$uploadDir.”‘,”https://wordpress.stackexchange.com/”, … Read more

Does the debug.log do log rotation?

No, it creates only one file. There is no log rotation involved. But… Sometimes “but” can be a good thing 😉 WP uses error_log for its debug log, so you can change its location using: ini_set( ‘error_log’, WP_CONTENT_DIR . ‘/debug-‘ . date(‘Y-m-d’) . ‘.log’ );

WordPress Ajax always returns a 404 error

This was very frustrating to figure out. I spent hours on this issue and discovered your problem is in this input: <input type=”text” name=”name” id=”name” size=”30″ value=””/> Try changing the input field name to anything but “name”, for example: <input type=”text” name=”user_name” id=”name” size=”30″ value=””/>

Is this a hacking script in function.php?

I would agree that there is a strong possibility of a hacked site with that code. The @file_put_contents statement is trying to write to your wp-admin folder. That’s not good. So I would recommend a de-hacking inspection. If you think your site got hacked, there are several (many) things you must do to ‘de-hack’ it. … Read more