Display random post on a page with post permalink in URL

What you are asking is how to redirect the visitor to a random post. Here you go: <?php /* * Template Name: Random Redirect */ query_posts( array( ‘showposts’ => 1, ‘orderby’ => ‘rand’, ) ); if (have_posts()) : while (have_posts()) : the_post(); header( ‘Location: ‘ . get_the_permalink() , false , 303 ); The syntax is … Read more

Custom MySQL Query with logic

Thank’s everyone for your attention. If anybody will need to query database with two postmeta, here is the code SELECT p.* , CASE WHEN m1.meta_value=0 OR m1.meta_value IS NULL THEN m2.meta_value ELSE m1.meta_value END meta_value FROM aka_v_posts p LEFT JOIN aka_v_postmeta m1 ON p.id=m1.post_id AND m1.meta_key=’_wpsc_special_price’ LEFT JOIN aka_v_postmeta m2 ON p.id=m2.post_id AND m2.meta_key=’_wpsc_price’ WHERE … Read more

Error sending array of inputs

As I said in a comment above, setting query_var => false for the custom taxonomy is not a solution because this will make term pages in frontend return a 404 error. Renounce to term pages in the frontend to make a simple form to work is far away to be a solution. Finally I’ve solved … Read more

Co-authors plus problems with query_post

Please don’t use query_posts. Just don’t. Create a new query with WP_Query. Secondly, I am not sure how you are trying to use multiple authors in the query but I assume you are using author and a comma separated string of IDs or author__in and an array. For example: $query = new WP_Query( ‘author=2,6,17,38’ ); … Read more

Order posts by condition

As Tom said, you should never use query_posts and should almost always pass any arguments as an array. I think this will achieve what you want: <?php // Arguments $args = array(‘ ‘nopaging’ => true, ‘terms’ => ‘featured’, ‘posts_per_page’ => 15, ‘orderby’ => ‘rand’, ‘order’ => ‘DESC’, ‘); // The query $the_query = new WP_Query( … Read more

pass query string on url to filter media

As per the given url http….url…/author/name?MediaTag=tag1, below code may helpful… if(isset($_GET[‘MediaTag’])) //It will check the value of MediaTag (from address bar after ?) { $tag1 = $_GET[‘MediaTag’]; //Assigning value of MediaTag to the variable if($tag1) //Checking if variable have some value or not { query_posts(‘cat=1&author=” . $post->post_author . “&order=DESC&tag=’ . $tag1 .’&posts_per_page=12′ . ‘&paged=’ . … Read more

How to filter query to display posts from parent category only?

I was finally able to get this to work using the filter provided by the plugin. The query uses [cat] to get the category which doesn’t support the include_children parameter. Therefore, I had to define the tax_query argument before unsetting [cat]. Here’s the function: add_filter( ‘miniloops_query’ , ‘miniloops_child_posts_filter’ ); function miniloops_child_posts_filter( $query ) { $query[‘tax_query’] … Read more

Show Only Posts Owned By Logged In User + my post

First, I second Q Studio comment: check Tom McFarlin’s post with a warning about using pre_get_posts. More specifically, pre_get_posts works everywhere, including RSS and dashboard, and you might want to exclude your logic from such places. That said, if I understood correctly what you are trying to do, you can achieve it by using author__in … Read more