Wrong or no posts
-
Can anybody help with this issueI’ve been battling with for days?
The task I thought should be simple but I’m missing something.I have a custom post type and each post type is assigned to a child category, I loop through the child categories and call a function each iteration that gets the posts assigned to it, or at least it’s supposed to.
If I remove the cat_idfrom args then all results listed (even though it only gets three at a time (for some strange reason).
If I add the cat_id then no posts get returned, I have checked the posts are correctly assigned to their categories and they are, I have echoed the ID’s to the page to check they’re present and they are but still with a cat in args I get no results.Here is the categories loop which appears to work fine:
$categories = get_categories(); foreach( $categories as $category ) { if ( $category->parent > 0 ) { $child_cat_ID[] = $category->term_id; $parent_cat_ID = $category->parent; $catty = $category->term_id; get_geo_services($category->term_id, $category->slug); } }And here is my function that should be retrieving the posts:
function get_geo_services($cat_id, $category_name) { echo 'Services in '.$category_name. ' with the cat ID of '.$cat_id; $args = array( 'post_type' => 'geo_service', 'cat' => '.$cat_id.', 'post_status' => 'publish', 'posts_per_page' => 20, 'orderby' => 'title', 'order' => 'ASC'); $loop = new WP_Query( $args ); echo '<div class="row">'; while ( $loop->have_posts() ) : $loop->the_post(); echo '<div class="col-12 col-md-4 col-lg-3">'; echo '<div class="service-card">'; echo '<h4 class="service-card-title">'; echo '<a href="'; the_permalink(); echo '">'; the_title(); echo '</a>'; echo '</h4>'; if ( has_post_thumbnail() ) : ?> <div class="service-card_image"> <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"> <?php the_post_thumbnail(); ?> </a> </div> <?php endif; echo '<div class="service-card_content">'; the_excerpt(); echo '</div>'; echo '</div>'; echo '</div>'; endwhile; echo '</div>'; wp_reset_postdata(); }Can anybody please help, I’m sure someone with WP expertise will be able to spot what I am doing wrong. Thank you in advance.
The blog I need help with is: (visible only to logged in users)
-
Hi there,
I’ve taken the time to look into your website and noticed that it’s actually using the WordPress.org software and is hosted by a different provider.
WordPress.org is the same foundational software we use here at WordPress.com, but it’s set up a little differently. Because of this, the specific help you may need can be different. To get the most appropriate help for your issue, I’d recommend posting your question in the official WordPress.org support forums, which you can find here: https://wordpress.org/support/forums/.
That said, I would also like to mention an alternative for you. You can migrate your website to WordPress.com. We are a managed-hosting platform, which means we take care of all the maintenance and security tasks so that you can focus on creating content for your website. We also offer dedicated WordPress support through both email and live chat to ensure your questions or issues are handled promptly and efficiently.
If this sounds like something that could interest you, we’ve built an easy-to-use tool specifically for migrating WordPress sites from other platforms to WordPress.com. You can learn more about how to use this tool here: https://wordpress.com/support/import-using-move-to-wordpress-com/
You can also take a look at our various plans and what they offer on this page: https://wordpress.com/pricing/
If you have any other questions or if there’s anything else you’d like to discuss, don’t hesitate to let me know.
- The topic ‘Wrong or no posts’ is closed to new replies.