Tag Info

New answers tagged

1

Use pre_get_posts instead.. function my_archive_query_override( $query ) { if ( $query->is_archive() && $query->is_main_query() ) { $query->set( 'orderby', 'rand' ); } } add_action( 'pre_get_posts', 'my_archive_query_override' ); For that user selectable part, you can use AJAX to accomplish that.


2

The title of question is inaccurate. I think you don't want to escape first post, instead you want to exclude current post. You can use the post__not_in argument in WP_Query. $args = array( 's' => 'searchTerm' ); //Check if we are in a post of any type if( is_singular() ) { $post = get_queried_object(); $args['post__not_in'] = array( ...


0

Try adding the offset parameter into the arguments.. $query = new WP_Query( array( 'offset' => 1, 's' => 'searchTerm') ); if ($query->have_posts()){ while ($query->have_posts()){ $query->the_post(); //echo the post } wp_reset_postdata(); } else { echo 'No results'; ...


1

I think you forgot to check if $the_query have posts. <?php $args = array( 'post_type' => 'testimonials', 'posts_per_page' => 1, 'orderby' => 'rand' ); $the_query = new WP_Query( $args ); ?> <?php if ( $the_query->have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); ...


0

How are you currently generating the login URL & handling the redirect? You should simply be using wp_loginout and passing the permalink as the redirect, and let WordPress handle everything else: <?php wp_loginout( get_permalink() ) ?> Or for a more custom implementation: <?php if ( ! is_user_logged_in() ) : ?> <a href="<?php ...


0

I believe that you're asking about post format and not post type. Assuming that's correct, you'll probably be using WP_Query to query all posts of the post format "Standard." However, as noted in this trac ticket, there's strangely no way to query for the standard post format. Instead you need to query for all posts NOT IN any other format. Alex King put ...


0

Took some time, figured it out. Just a matter of working with the array of data from the custom taxonomy used in the advanced custom field: <div class="container"> <?php $rows = get_field('asset'); if($rows) { foreach($rows as $row) { echo '<div class="mix img ' . ...


0

Looking at the code as is, it appears that after you finish your foreach, $term will be set to the last object in the $terms array. Nothing further happens with $term, so when you use $term->name in your $rows foreach, the value will always be the same.


2

You cannot use the same object of WP_Query twice. Therefore you need to create another one with a tax_query parameter to fetch posts which are not assigned to any term. //fetch all reviews which have no assigned term in 'review-product' $taxonomy = 'review-product'; $post_type = 'reviews'; $args = array( 'post_type' => $post_type, 'tax_query' ...


1

instead of a counter variable, you can use the build-in loop counter; as I don't know how you need to wrap the posts into the individual divs, here just an example structure (only to be used with 5 posts per page): <div class="col-lg-12"> <div class="row"> <?php if ( have_posts() ) : ?> <?php if ( ...


3

First: don't use query_post for secondary loops. It alter the main query and you can end up with wire results. Instead use a new WP_Query instance. See this question for detail info. Now with your proble. You are using the "cat" parameter and that is for "category" taxonomy, not for your custom taxonomy. You should use the tax_query parameter instead: ...


3

You have a few flaws in your code that are causing this failure First of all, and most important of all, never (my emphasis) use query_posts to construct a custom query. Note: This function isn't meant to be used by plugins or themes. As explained later, there are better, more performant options to alter the main query. query_posts() is overly ...


0

What I would do is use multiple loops while tracking the ID of the post recorded in the previous post and skipping over it in the next loop so it is not repeated. I'll show you what I mean. I'm also making use of the WP_Query class. <div class="container"> <div class="row"> <?php $args = array( ...


0

This is quite a vast question to answer, so I'm not going to go into depth, I'm just going to cover the essential points. You'll need to create a custom query to get all the data from your pages. Use WP_Query to create your custom query. Here is a basic query from the codex to get your pages <?php // The Query $the_query = new WP_Query( ...


0

You might want to check out this post, as your post is linked to that question. That should explain most of your question. As for your code, move that outside the the loop. You were nearly there with your code. Check out get_terms in the codex to see which objects you can use that is returned by the function. You can use $term->description instead of ...


0

Well you can make a single template for the entire site and may call different page content in different <div> using this code: <?php $page_id = 47; $page_data = get_page( $page_id ); echo $page_data->post_content ; ?>


1

Well I think I seem to be doing what I was intending too. Thanks @Milo for pointing me in the right direction! As You can see below I used the get_page_template_slug(); and str_replace() to filter through the templates used per page. Can someone Verify that this is a viable option? $args = array ( 'post_type' => 'page', ...


3

Try this: We declare an incrementer at the top of our outter loop called $popularLoop to keep track of how many popular loops we've been through, we assume we're going to at least hit 1. Inside our Inner Loop (popular) we need to set how many posts per page we're going to load, multiple that by how many popular loops we've been through and that is going to ...


0

Not tested but you can try this: $args = array( 'posts_per_page' => 4, 'post_type' => 'post', 'meta_key' => 'meta-select', 'order' => 'ASC', 'orderby' => 'meta_value_num', 'meta_query' => array( array( 'key' => 'meta-select', 'value' => ...


1

The reason why your check didn’t work is because is_singular() checks for post types, not for post IDs. is_singular( 'product' ) checks if the current post is of the type product, nothing else. The comparison 2295 === get_the_ID() does exactly what you need.


0

@toscho was correct. I replaced this: <?php if ( is_singular( '2295' ) ) : ?> With this: <?php if ( 2295 === get_the_ID() ) : ?>


1

Before we begin, I must point out the following: You're using a file in your theme to send AJAX requests to, don't do this, there are security implications. Instead, use the WP AJAX API, you'll be able to remove half the code and make it work without having to change the URL everytime your site moves You used query_posts to make your query, this is almost ...


1

You have to reset every instance of a custom query, otherwise you will get unexpected output from any other query there after Simply use wp_reset_postdata() after every custom query. Example <?php $args = array( 'numberposts' => '1', 'meta_key'=>'_thumbnail_id' ); $recent_posts = wp_get_recent_posts( $args ); foreach($recent_posts as ...


0

Use get_post_format() inside your loop: if (have_posts()) : while (have_posts()) : the_post(); $format = get_post_format(); if (false === $format) { get_template_part('content', get_post_format()); } endwhile; twentyfourteen_paging_nav(); else : get_template_part('content', 'none'); endif;


0

Don't use query posts ever, my emphasis. It is just a bad function to use Note: This function isn't meant to be used by plugins or themes. As explained later, there are better, more performant options to alter the main query. query_posts() is overly simplistic and problematic way to modify main query of a page by replacing it with new instance of the ...


4

The Automatic Sponsor Posts Injector: Here's one idea based on my answer for the question: How to show Y number of custom posts after every X normal posts? I hopefully made it a little bit more useful here on Github, but it may be refined much more (future work). The SponsorPostsInjector class will help you to automatically inject the sponsor posts into ...


1

One way is to have a single front-page.php and then using get_template_part(), to show different content based on user choice. Rough code: get_header(); $layout = get_option( 'front_page_layout', 'default' ); get_template_part( 'front-page', $layout ); get_footer(); After that you need to create a file for every layout, they should be called, something ...


0

There is only one option, the page templates one. This is how 99% of the themes work and what wordpress users and implementators are used to. You can try to be unique but no one will appreciate it.


1

This is a php logic / variable issue. You output $fullname whether or not it has been set inside that iteration's foreach. So for projects that never enter the foreach to set $fullname, it still contains whatever the last iteration had set it to. Set it to an empty string before the foreach so it only contains a name if it enters the foreach.


1

You're not adding HTML code to your file, you're adding invalid PHP. To recap, in PHP everything between <?php and ?> is PHP code. So this is valid PHP: <?php echo 'hello world';! ?> This is also valid: <b><?php echo 'hello world'; ?></b> This is not valid: <?php <b> echo 'hello world'; </b> ?> Why? ...


2

You are including HTML elements without closing the php tags. Also, the last one should be endif, not endwhile. <?php if (have_posts()) : ?> <ul> <?php // Start the Loop. while (have_posts()) : the_post(); /* * Include the post format-specific template for the content. If you want to ...


2

This seems to work: while( have_posts() ): the_post(); the_content(); endwhile; $my_query = new WP_Query('page_id=40'); while ($my_query->have_posts()) : $my_query->the_post(); $do_not_duplicate = $post->ID;?> <div class="entry"> <?php the_content('read more &raquo;'); ?> </div> ...


0

first of all you named your page template "Post Archive" not "All Posts"! and for a quick and easy solution check the link below: Creating an Archive Template


1

I would tend not to go with wp_get_recent_posts or even get_posts for custom queries like this. By default, template tags like the_excerpt() is not available to these functions, and you have to make use of setup_postdata($post) to have access to these template tags. I would personally use WP_Query in a case like this which is more flexible, specially when ...


0

It looks like the two previous answers will get you close, but as I understand it, you might need to change the foreach loop into a second wordpress loop call, after the custom query (see an example here in the "examples" section): The reason I suggest using the wordpress loop is that the function the_excerpt() only works inside the standard loop framework. ...


0

You can get the image using this code: $src = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'medium', false, '' ); $thumbnailSrc = $src[0]; where 'medium' is the thumbnail size, this can be changed to thumbnail, large or any special size created with thumbnail support on functions.php ej. add_image_size( 'postslider', 680,310, true ); ...


0

You can use: get_the_post_thumbnail($recent['ID'], 'post-thumbnail'); in order to get the thumbnail. Unfortunately, there is no way to get the excerpt, you can however trim the content using PHP. Alternatively, there's a hook I haven't used before, you can try it and see i its works for the excerpt: get_post_field();


1

As Tom said, that will never work, as the main query have already executed. The only way to achieve that is to alter the main query before it is executed. There is a action hook for that, pre-get_posts and this is the correct method to alter the main query. Example: function wpse_custom_ppp( $query ) { if ( !is_admin() && ...


1

Your problem is your query, but before I cover that, there are some concerns that are getting in the way of seeing the problem. Firstly, every single line has . It's like hanging up and dialling the number again at the end of every sentence in a telephone conversation, and it's so much more effort to type and read. So lets fix that: <?php $query = new ...


1

You can use get_the_category inside the loop to get the category/ies a post is assigned to. To get a list of available member variables available, see get_categories. I would suggest to target the first category only, which will also be the parent category if the post is assigned to only one parent and some of the parent's child categories. Here is an ...


0

Replace all your pagination code with this and change the classes to match your CSS or you could search for the classes included in this code in the Twenty Twelves themes style.css file. <nav class="nav-single"> <span class="nav-previous"><?php previous_post_link( '%link', '<span class="meta-nav">' . _x( '&larr;', 'Previous post ...


1

EDIT Referring back to one of your previous questions I've answered, you are using custom taxonomies, so this is most likely your problem then. You then have to set the taxonomy parameter accordingly. See my original answer ORIGINAL ANSWER There are a few things to check here Where is your next_post_link. Did you leave out by default? Are you using ...


0

The third parameter in your previous_post_link() function call is set to true, which will restrict any results to those posts in the same category as the current post. Try setting the third parameter to false (or remove it entirely), and see if that makes a difference. If the third parameter is intentional, make sure you actually have posts in the same ...


0

EDIT: Moved $i = 0 outside the loop. That should get you the full list of categories. $get_posts = new WP_Query(); $i = 0; $get_posts->query($args); if($get_posts->have_posts()) { $cats = array(); while($get_posts->have_posts()) { $get_posts->the_post(); $post_categories = wp_get_post_categories( get_the_ID() ); ...


0

EDIT You are saving the categories in the array. This is very good. I am changing this block on code. See the modified code $cats = array(); while($get_posts->have_posts()) { $get_posts->the_post(); $post_categories = wp_get_post_categories( get_the_ID() ); foreach($post_categories as $c){ $cat = ...


0

The way I read you question is that you need 12 posts per page in this taxonomy regardless of the current term been displayed. This can be easily done with pre_get_posts. You should never change the main query for a custom query on archive pages. Have a read on this answer I've recently done on this subject. Use the is_tax() conditional to target the ...


0

What you are describing is loosely related to "faceted search", but you aren't quite searching. :) In a nutshell you would need to: Communicate information about "selected" taxonomy to the page, this might be done with GET query or rewrite endpoint Generate links (or whatever interface you have) accordingly Adjust main query (!) of the page via ...


1

<?php if (have_posts()) : while (have_posts()) : the_post(); endwhile; else: _e('No blog found.', 'polymer'); endif; ?> if(have_post) condition is to check if the page contain post, while(have_posts) condition if there is more than one post display in loop, the_post() is used to display the post if(have_post) ...


0

Would the has_excerpt() function work? The Codex says of it: Whether the current post has an excerpt.



Top 50 recent answers are included