Articles of posts

Get latest post from categories

I have 3 categories: Travel, Destination and Tips. I’ve been trying to get the latest post from each categories then put them into an array. Here’s what I have in mind. //GET CATEGORIES //I have this code but this only selects one category $args = array ( ‘post_per_page’ => 1, ‘cat’ => 16 ); //SELECT […]

Use posts_where to exclude posts ids from wp_query

I want to use posts_where to exclude an array of posts ids from all queries in my site. The array containing the posts ids depends on the user that is logged in. Can someone please tell me how to use the filter posts_where to exclude a list of posts ids from all queries in my […]

List all posts in taxonomy term

I have a custom post type called anime and a taxonomy called series. If I view any post and that post belongs term Banana it should list all the posts in term Banana in a dropdown list. Here’s the code so far: <?php $category = get_terms( ‘series’ ); $catID = $category[0]->term_id; $args = array( ‘numberposts’ […]

How to set a certain Custom Template to a Single Blog Post

I need to set a custom created template to be used whenever a single blog post is displayed. I can see how to assign custom templates to pages under Page Attributes > Template, but how do I tell my WP site to use a custom template when displaying a single blog post?

Retrieving posts by their date and category

I’m trying to create a plugin for displaying post titles and dates (which will be displayed as links to those posts) of a specific date range and category. So far I have managed to get to display the posts in between the dates, but I can’t wrap my head around the WP category thing. I […]

Hide thumbnail if there is a gallery on the post

In a post I want to always show one of two options- If the post has nothing but a thumbnail image show the thumbnail. If the post has both the thumbnail and a gallery then show the only gallery and don’t show the thumbnail. I am using a plugin for the gallery called metaslider. but […]

Reset/Reorder posts ID in the MySQL wp_posts table

I have a WordPress site that is considerably popular. I am in the process of optimizing the site before adding other plugins such as the WPML plugin which I suspect will be using custom post types. The site already has other plugins which I don’t suspect use the wp_posts table for custom post types except […]

How to compare post tags?

I want to compare post tags. If the tags match, then display the matching post. For example, I have a post called “ONE” with some tags and another post called “TWO” with some tags. I want to compare both post’s tags and if they match, then display that post.

Bulk update post slugs through database

Is there a way to bulk update permalinks through the database? cause I have like 20k posts and all I want to do is add a prefix to the permalink. I could just manually update but that’s too tiresome for 20k posts. For example if post url is I want to change it to […]

Get images from the post

Using Add Media I am inserting images in the Post.I want to reterive these only these images on the single post page.I am using get_attached_media function to reterive these images.But it returns an empty array. <?php $media_image = get_attached_media( ‘image’, $post->ID ); //print_r($media_image);?> <div class =”single-post-flex-slider”> <ul class=”slides”> <?php foreach($attachments as $image){ $image_attr = wp_get_attachment_image_src( […]