Tag Info

New answers tagged

1

I am giving solution of my own problem :) <?php $descendant= array('child_of'=>54); $categories = get_categories($descendant); foreach($categories as $category) : echo $category->name; endforeach; ?>


0

In your $args array, you should be able to add 'posts_per_page' => -1 to show all products. The result would look like this: $args = array( 'post_type' => 'product', 'paged' => $paged, 'posts_per_page' => -1 );


0

function get_custom_excerpt( $content, $link ){ $content = some_function_to_handle_html_tag(substr($content, 0, 100)); // EDIT: need to be customized with a regex for proper output $content .= ' <a href="'.$link.'"> more... </a>'; return $content; } function some_function_to_handle_html_tag(){ //a regex to check last occurance of ...


0

If you store your last post ID in a variable from the first loop you can use post__not_in in the second loop to exclude the Id. Example adapted from Wordpres Class Reference/WP Query $query = new WP_Query( array( 'post_type' => 'post', 'post__not_in' => array( $excluded_post_id ) ) ); You can exclude any number of posts by ...


0

to get the content of the post outside the loop you can write something like this global $post; $content = $post->post_content; if ( !empty( $content ) ) : echo $content; endif;


-1

Solution was to remove the style tag and and write the background styling right into the .featured_box div. Thank you to @ckhicks on Twitter for the solution, and thank you everyone else for trying to help out too <3 <?php $background = wp_get_attachment_image_src( get_post_thumbnail_id( $page->ID ), 'full' ); ?> <a href="<?php ...


0

This is just a concept which you can try. By default, you cannot sort within the loop. You have, according to my knowledge, have two choices Create two loops and merging them. This, however, I would not recommend. Pagination and offsets are a nightmare if you are not completely comfortable with it Run your loop as normal, and pushing the results into two ...


0

This will get you next 10 posts on single post template. <?php global $post; $current_post = $post; for ( $i = 1; $i <= 10; $i++ ) { $post = get_previous_post(); // this uses $post->ID setup_postdata($post); get_template_part( 'content', get_post_format() ); } $post = $current_post; // restore ?> ...


0

You have to read the documentation thoroughly, for example: The second is during The Loop. WP_Query provides numerous functions for common tasks within The Loop. To begin with, have_posts(), which calls $wp_query->have_posts(), is called to see if there are any posts to show. If there are, a while loop is begun, using have_posts() as the condition. ...


0

I used a simple solution... I found the class name of the gallery which is .photogalleria so i changed the css display to none in my css. .photogalleria{ display:none; }


1

You need something like this in you functions.php file, I'm using the action Pieter suggested. function add_custom_post_type_to_query( $query ) { if ( $query->is_home() && $query->is_main_query() ) { $query->set( 'post_type', array('post', 'article') ); } } add_action( 'pre_get_posts', 'add_custom_post_type_to_query' ); ...


0

The Problem It's been awhile since I have messed with HTML, but if I remember correctly the <style> tags would be global. To elaborate: <style></style> would be as if you appended it to the end of your css file, but if you did something inline, such as <h2 style="color: red;">test</h2>, it would only be applied to that html ...


1

Take a look at the default Twenty Fourteen theme code in index.php <?php if ( have_posts() ) : // Start the Loop. while ( have_posts() ) : the_post(); /* * Include the post format-specific template for the content. If you want to * use this in a child theme, then include a file called called ...


0

What you are doing here is on the Bad Ideas list. While you can replace the query in template that tends to break things, especially pagination. In simplified form let's say you have 10 testimonials and your WP settings are 5 posts per page: your template thinks there are 10 / 2 = 5 pages worth of testimonials but WordPress thinks there are only 10 / 5 = ...


2

Lets first start with a bit of knowledge-base: the_content is this /** * Display the post content. * * @since 0.71 * * @param string $more_link_text Optional. Content for when there is more text. * @param bool $strip_teaser Optional. Strip teaser content before the more text. Default is false. */ function the_content( $more_link_text = null, ...


-2

<?php $related = get_posts( array( 'category__in' => wp_get_post_categories($post->ID), 'numberposts' => 5,'post_type' => 'news', 'post__not_in' => array($post->ID) ) ); if( $related ) foreach( $related as $post ) { setup_postdata($post); ?> <li> <?php the_post_thumbnail(); ?> <a ...


0

Your code has 3 problems you use one DB query to save another DB query. You query a transient value instead of the post table which might or might not be faster but you don't save the penalty of communicating with the DB. You should not store objects in transients or options. According to the documentation values there are supposed to be scalars only which ...


1

I have actually worked on a post yesterday (check it out here) and was hit by the same problem. I'm also new to the Transient API, never actually worked with it :-). The problem here is that for a specific loop you need to use a certain value outside of your transient. You are simply storing the wrong values, and because of this, you are getting these ...


0

If we want to avoid any filters and manual SQL queries, we could try (untested): $args = array( 'post_type' => 'foods', 'posts_per_page' => 5, 'post__in' => array_unique( wp_list_pluck( get_comments( array( 'user_id' => get_current_user_id() ) ), ...


0

Do not use query_posts, and also do not replace the main query with a custom query. This causes more issues than solving the one issue you had before with the main query. I've done a complete post on these issues recently that you can check out here According to your query, the only two things you need to change is posts_per_page and order to do this, you ...


-2

Here is a workaround: Create a menu named Category Menu register_nav_menu( 'category-menu', "Category Menu ); Now your client can configure the menu as he pleases. All you have to do is paste the code below where you want it to be displayed and voila wp_nav_menu('category-menu');


1

I think the most sane way and easiest way of doing this is to unset the first value in the returned array, and then adding it back at the end of the returned array before your foreach loop For this to work, you will need to sort your categories by ID as you need to take category ID 1 and add that to the back. Something like this will work <?php $args = ...


1

Use query link this. You are checking posts in $the_query. but you have used $query. <?php $custom_query = new WP_Query( 'posts_per_page=4' ); if ( $custom_query->have_posts() ) : while ( $custom_query->have_posts() ) : $custom_query->the_post(); ?> <h2><?php the_title(); ?></h2> <?php ...


1

If it's a child page, the post_parent will be a non-zero value, so you could check for that: if( 0 == $post->post_parent ){ // no parent, get children of this page $childargs['post_parent'] = $post->ID; } else { // has parent, get children of parent page $childargs['post_parent'] = $post->post_parent; } This is assuming your child ...


1

From your functions file function remove_home_category( $query ) { if ( $query->is_home() && $query->is_main_query() ) { $query->set( 'cat', '-4' ); } } add_action( 'pre_get_posts', 'remove_home_category' ); This code alters the query before the actual query is run so is the most efficient hook to modify the loop in this ...


1

The very first line contains an incomplete opening PHP tag, it should be <?php not < ?php or some other variation. Also if statements don't require a semi-colon after them. Your code is also not indented correctly. A good editor will auto-indent code for you automatically. A good editor will also syntax check and point out errors as you type them. ...


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 ...


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;



Top 50 recent answers are included