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

Using file_exists to check file in Uploads

You can’t use a file url in file_exists() like this: file_exists( “http://example.com/wp-content/uploads/Example_Name_2_SM.jpg” ); You should rather use an absolute file path, for example: file_exists( “/absolute/path/to/wp-content/uploads/Example_Name_2_SM.jpg” ); Then you should try $meta = get_post_meta( $post->ID, ‘_meta_example_name’, true ); $file = $upload_basedir . “https://wordpress.stackexchange.com/” . $meta . ‘_7_SM.jpg’; if ( file_exists( $file ) ) { //… } … Read more

Create Image Uploader for Widget

Let’s face it in detail: The registered sidebar (with the ID left-sidebar) has two arguments to wrap the whole widget (before_widget and after_widget) which you can output via echo $before_widget and echo $after_widget in your widget (see my version below): <?php // Register sidebar if (function_exists(‘register_sidebar’)) { register_sidebar( array( ‘name’ => ‘Left Sidebar’, ‘id’ => … Read more

Display posts by month

As said in a comment, you can do this in one query. The principle here is to only display the date heading if the post date’s month of the previous post does not match that of the previous post FEW NOTES Before I start, a few notes: Never use query_posts, except if you really need … Read more