Tag Info

New answers tagged

0

I figured out the answer to my own question (finally!). I'm using the NineToFive template and I guess by default there's a limit on the number of search results that's returned (I'm not sure if that's a WordPress default; maybe someone can clarify that). I changed my query to this: $s = new WP_Query(array('s' => $search_term, 'posts_per_page' => ...


0

Untested, but I think you'd need to do two separate queries and merge them together: $args = array( 'post_type' => 'featured-posts' ); $featured_posts = get_posts($args); $args = array( 'post_type' => 'review-posts', 'category_name' => 'featured-category' ); $review_posts = get_posts($args); $result = array_merge($featured_posts->posts, ...


1

Here is a start. Create a template called content-related.php Inside that paste the following code <?php /** * The default template for displaying realted posts * * @package WordPress * @subpackage Pieter Goosen * @since pietergoosen 1.0 */ wp_reset_postdata(); global $post; // Define shared post arguments $categories = ...


0

Have you tried doing a query on both post types and including the category? I suspect that it will look only for posts in the featured category, then limit by the two post types, but nonetheless it's worth a try. $args = array( 'post_type' => array( 'featured-posts', 'review-posts' ), 'category_name' => 'featured-category' ); $res_posts = ...


2

Yes but not in an easy simple way via the order parameters. I would suggest that you: Maintain a 3rd post meta Whenever you change the first or second, add them together and set the 3rd meta to contain the sum of the new values Order by the 3rd value The alternative is to write your own SQL query from scratch and all the horrors and disadvantages that ...


0

You could force is_single when replacing the main query: $draft_post_query = new WP_query(array( 'post_status' => 'draft', 'post_type' => array('post'), 'post__in' => array($post_id) )); $draft_post = $draft_post_query->post; global $wp_query, $post; $wp_query = $draft_post_query; $post = $draft_post; $wp_query->is_single = true; ...


0

I was looking for another answer and stumbled on this, thought i could help. If you looking to exclude the most recent post(s) you may be able to use wp_get_recent_posts() to retrieve the ID(s), and then use 'post__not_in' => array(#,#) in your WP_Query to exclude those resent posts. Tested this a little and found this to work for getting ONE post to be ...


2

There are no methods the_content() or the_title() of your query object. These: $review_query->the_content(); $review_query->the_title(); should just be the_content(); the_title(); If you had debugging enabled you would see an error informing you of this.


0

At first glance, I see that your query is calling for 'post_type' => 'page' while the taxonomy is registered on the post object type. Changing the post type to post ('post_type' => 'post') should fix the problem.


1

I wouldn't use custom page templates merely for changing the layout of the blog posts index. Using page templates for the blog posts index bypasses the core handling for display of the blog posts index (which per the template hierarchy uses either home.php or index.php to render). Edit I never...said that I want to change layout of the blog posts ...


0

You don't need to loop over each category & query them one-by-one, just query them all once: $query = new WP_Query( array( 'post_type' => array( 'service' ), 'category__in' => $ucategory, 'posts_per_page' => -1, ) );


1

Per the Codex: relation (string) - The logical relationship between each inner taxonomy array when there is more than one. Possible values are 'AND', 'OR'. Do not use with a single inner taxonomy array. So you are on the right track, but your tax_query is wrong. relation is part of the outer tax_query array and not part of the top level query ...


0

Thanks Pat J I'have got solution now: <?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; ?> <?php $offset = ($paged - 1) * 4;?> <?php $kat = get_field('kategory');?> <?php $query = new WP_Query(array('offset' => $offset,'post_type' => 'modelki', 'taxonomy' => $kat, 'posts_per_page' => '4')); ?>


0

Your queries are showing the same output, because they are identical Here is your first queries arguments: $args = array( 'orderby' => 'title', 'order' => 'ASC', 'posts_per_page' => 5, 'paged' => get_query_var('paged'), 'tax_query' => array( array( 'taxonomy' => 'store-category', 'field' ...


-1

You're using the argument 'posts_per_page' => '4' in the WP_Query. That is why only 4 posts are showing up per page.


-2

You use the best way:) Maybe, if you want to optimize your query you can use posts 2 posts plugin. You will not need to filter the query. Link - https://github.com/scribu/wp-posts-to-posts/wiki


0

They're both doing the same thing. If you don't pass a post ID, get_the_title() will just use the current post and go about it's business. The performance difference between passing a postID and not passing a postID is, if anything at all, is extremely minor. get_the_title() Codex get_the_title() Core Function


2

If you hook your localize script function to wp_enqueue_scripts, then you will have access to the global $post variable. As long as you pick a hook at or after 'wp' you should have access to the global $post. <?php add_action('wp_enqueue_scripts', 'YOUR_NAME_scripts'); function YOUR_NAME_scripts() { wp_enqueue_script('YOUR_NAME-js'); ...


1

The problems on set a query parameter to unexistent value are 2: The query will run, so even if you already know will be no results there is a little performance price to pay WordPress queries has 19 different 'posts_*' filter hooks ('posts_where', 'post_join', etc..) that act on query, so you can never be sure that even setting unexistent param the query ...


2

Try 'post__in' => array(0) Simple and to the point.


1

Curiously there is no clean/explicit way to short circuit WP_Query. If it's main query you might work something out around WP->parse_request(), there seems to be relatively recent (3.5) do_parse_request filter there. But for WP_Query itself dirty hacks are usually in order, such as short-circuiting SQL query by adding AND 1=0 via posts_where filter, ...


0

pre_get_posts pre_get_posts is used to alter the main query for posts so the is_home() conditional tag will work. You can also use the is_post_type_archive() conditional tag to alter the query on CPT archives like so. add_action( 'pre_get_posts', 'limit_cpt_items' ); function limit_cpt_items( $query ) { if( $query->is_main_query() && ...


0

The first way, using the pre_get_posts action will modify the main query before the page loads. The second way will create a new query. It is much better to alter the main query than to create a new query.


2

See Taxonomy Parameters in Codex. First — areas should probably be in your tax_query as well. Second — you probably need to make use of operator argument in queries (inner ones). I am not sure without testing this out but AND seems like it would for more strict matches than default IN for your mandatory types/features logic.


0

You have a structural problem with your data. Serialized data in the database is terrible if you need to search over pieces of that serialized data. There is no reliable, efficient, and certainly no easy, SQL query to search over serialized data. "serialization" is a PHP mechanism. It isn't SQL. To the database that is just a string. Your only SQL choice ...


0

Just as @Rarst suggested, you must have your $args defined within your function. You could solve it by using global variables, but we don't want too many such variables flying around! Check out the PHP docs on the scope of a variable or write your code in a class. You can also simplify your query. Here's an example how your function could look like: ...


0

UPDATE! OK!!! Woooohooo! Found out what it was.. I should have been calling if have posts before the call for $tax->name; Here is my final, and working code! :) <?php /**********************************************/ // CUSTOM WINE MENU SHORTCODE /**********************************************/ add_shortcode( 'wine_list_per_cat', 'wine_list_per_cat' ); ...


1

The Transient API saves data inside the database, which isn't as effective as APC, but a similar workflow as used for transients can be used for APC. It is important to check if APC is available and active, so its functions are usable. Because this isn't always the case, it is to consider to add a alternative to APC via Transient API and combine those two ...


1

Regarding the number of pages displayed, read through the arguments for paginate_links, specifically end_size and mid_size. As for the 404- The problem is there is no page 3. Whether or not a page returns content or loads the 404 template is based on the results of the main query, not your custom query you run in the template. If this is a page post type, ...


0

I discovered the problem by inspecting the actual SQL created by WP_Query. I realized that the generated SQL query has 2 INNER JOINs, one for the meta_key and another for the actual meta_query. Basically on one hand it is filtering those films that have a showings_%_start_datetime in the next seven days, and on the other hand (independently) it is ordering ...


1

$port_query->the_post(); should set the $post global. That isn't the problem. The problem is that the you are trying to use $post before your secondary Loop runs (99% sure). You've hooked the bkg_featured_image() function to wp_head. wp_head runs in the header of the document, which, unless you are careful, will run before the other template code. If ...


0

WP_Query does use $post. A full list of Methods and Properties can be found In the codex here. Are you sure that all your Portfolio items have featured images? you might want to use 'meta_key' => '_thumbnail_id', in the arg to make sure the random Portfolio has an image. you could also check in the template using if( has_post_thumbnail( $post->ID ) ...


1

If you poke through WP_Query the set of queried posts is saved into posts property and current post gets assigned to post one (each time loop iterates). So you could do $connected->posts[0] if you need to just fetch that, but it might be more convenient to do $connected->the_post(); then $connected->post if you need to skip first one and process ...


1

WP_Query itself can't do that logic internally but you can easily create the query dynamically. $args = array( 'meta_key' => 'name', 'orderby' => 'meta_value', 'order' => 'ASC', 'posts_per_page' => '-1' ); if ($post->ID == 1) { $args['category_name'] = 'first'; } elseif ($post->ID == 2) { $args['category_name'] = 'second'; ...


0

You should also include the $args argument. Here is an example where the sort order of topics is changed for just one forum: //* Change sort order of Topics within a specified bbpress forum function my_custom_display_topic_index_query ($args) { $thisforumid = bbp_get_forum_id(); if($thisforumid == 43135) { $args['orderby'] = 'date'; ...


0

If you want your posts based on different categories you should use category_name or cat as category id. For example; <?php $test = new WP_Query('cat=1&showposts=1'); // where 1 is the id of your cat ?> Or <?php $test = new WP_Query('category_name=errands&showposts=1'); ?> Also, you need to call wp_reset_postdata(); after each ...


2

I always recommend installing WordPress manually yourself. Some companies will insert a link crediting the hosting provider for the install. In the past, I've experienced 1-click installations that are not running the latest version of WordPress. In terms of migrating your website, you should follow this guide: http://codex.wordpress.org/Moving_WordPress. ...


0

If I understand correctly, the book and the reviews share same taxonomy. Then is just a matter of get the taxonomy term for the book in the single-books.php, save it in a variable and then run a query using that variable for the 'tax_query': if ( have_posts() ) { the_post(); // get the term for the current book and save in a variable $book_terms = ...


1

You have a couple of mistakes here. Firstly, if you need to check if you have a specific post format, use has_post_format( $post_format ). So if you need to something specific for post type video, you will do something like this if ( has_post_format('video')) { <--show video maybe--> } Secondly, standard is not actually a post format. When no ...


1

From the Codex (emphasis mine): This Conditional Tag allows you to determine if you are in any page template. Optionally checks if a specific Page Template is being used in a Page. This is a boolean function, meaning it returns either TRUE or FALSE. This tag must be used BEFORE The Loop and does not work inside The Loop (see Notes below). ...


0

sorry for no answering before, I completely forgot it: I did not use any name__like or filters, this is how I finally made it: $categoria = $_GET['categoria']; $filtro = $_GET['texto']; $args = array( 'post_type' => 'post', 'tax_query' => array( 'relation' => 'AND', array( 'taxonomy' => 'category', ...


2

You could try this instead: $bc_args = array( 'post_type' => 'data', 'data-category' =>'insurance-rate', 'order' => 'DESC', 'orderby' => 'meta_value_num', 'meta_query' => array( array( 'key' => 'interest_rate', 'value' => (int) $i_rate, 'type' ...


2

I think this is what you want. base is set via home_url(), format is page/%#%/, search query arg is added via add_args if it exists: $args = array( 'base' => home_url( '/%_%' ), 'format' => 'page/%#%/', 'current' => max( 1, get_query_var('paged') ), 'total' => $temp->max_num_pages, ); if( isset($_GET['s']) ){ ...


1

Totally untested and I'm not 100% sure I understand your question, but this should (in theory) get 5 posts that share any of the same venues as the current post. I would probably suggest adding some Transients to this so that you aren't constantly running queries. If it doesn't work, I suspect the syntax of my tax query is a little off. It always gets me ...


1

Your ampersand is getting encoded, try: get_page_by_title( html_entity_decode( $title ) );


2

All media (somewhat incorrectly) in the $wpdb->posts table will be "attachments" whether actually attached or not. "Attachments" that are actually attached will have a post_parent other than 0, so what you need are all of the attachments that have a 0 in the post_parent column, if I understand you. $args = array( 'post_type' => 'attachment', ...


0

<?php if ( $post->post_type == **'post type name'** && $post->post_status == 'publish' ) { $attachments = get_posts( array( 'post_type' => 'attachment', 'posts_per_page' => -1, 'post_parent' => $post->ID, 'exclude' => get_post_thumbnail_id() ) ); if ( $attachments ) { ...


0

Why not giving all posts the meta attribute with a custom value? I mean, you can set all posts to featured = no/false/0/low-numeric-valeu and then change to yes/true/1/high-numeric-values all those that should be featured and they will get ordered, won't they?


0

I don't think your code does what you think, as it is only ever set to a single post from one of your loops. You description doesn't really match that logic. To prevent duplicates you need to accumulate an array of IDs with each Loop. $do_not_duplicate[] = $post->ID; I think the space you are seeing is the result of your echoing markup even though ...


0

You can simplify things by using the date_query of WP_Query(), instead of the posts_where filter. You can then try the following (untested): // Fetch from the 'featured' category $args = array( 'posts_per_page' => 1, 'category_name' => 'featured', 'date_query' => array( array( 'after' => '1 ...



Top 50 recent answers are included