Get post content from another section in custom single page

Multiple loops in the same page <?php // this is for customer posts $args = array( ‘post_type’ => ‘customer’ ); $the_query = new WP_Query( $args ); ?> <?php if ($the_query->have_posts()) : ?> <?php while ($the_query->have_posts()) : $the_query->the_post(); ?> <?php // loop here the_title(); the_content(); ?> <?php endwhile; wp_reset_postdata(); else : ?> <p><?php _e( ‘Sorry, no … Read more

I have broke my pagination, same posts on all pages (index.php)

I seem to have fixed the pagination issue with the custom loops, not entirely sure how it works, but it does seem to work. I have changed the custom loop to the following; <?php $paged = ( get_query_var(‘paged’) ) ? get_query_var(‘paged’) : 1; $the_query = new WP_Query( array( ‘post__not_in’ => get_option( ‘sticky_posts’ ), ‘posts_per_page’ => … Read more

Get the image src and href data from posts

You can use preg_match_all to perform a regular expression match on the content of the post. <div id=’hitstatAdminMain’> <?php $args = array(‘post_type’ => ‘post’, ‘posts_per_page’ => -1); $query = new WP_Query($args); if ($query->have_posts()) { while ($query->have_posts()){ $query->the_post(); // Store the current iterated posts content in a variable $content = get_the_content(); // Perform a global regular … Read more

Echoing a CSS class based on category of post in a list

get_category(’91’) is always going to return an object of category ID 91’s data. This means your if statement is always going to return as true. You need to get the current iterated posts assigned category ID and then check if it is 91. <!– Return objects of current iterated posts associated categories –> $categories = … Read more

How include css class based on post ( in loop ) slug?

The error you get is produced by $slug = get_post( $post )->post_name; because there is no post_name on a 404 page. So, to prevent this error you must structure the function in a way it doesn’t get to this line when it is called on a 404-page. Like this: add_filter (‘post_class’, ‘fl_pages_bodyclass’); add_filter (‘body_class’, ‘fl_pages_bodyclass’); … Read more

Grabbed Post ID under WP loop, but still couldn’t Print Post title

Since you’re in a Loop, you don’t need to grab the post ID or use get_the_title(). Instead, replace line 2 and 3 of your code with: the_title(‘<h1>’, ‘</h1>’); Or, if you want to include a link as well: <h1><a href=”https://wordpress.stackexchange.com/questions/272948/<?php the_permalink(); ?>”><?php the_title(); ?></a></h1>

Loop returns the current page’s permalink and guid instead of the post in the loop

I’m actually surprised that your code is working. There are several typos in it that should be throwing fatal errors. global $post; $args = array( ‘posts_per_page’ => -1, ‘post_type’ => ‘post’, ); $the_query = new WP_Query( $args ); if ( $the_query->have_posts() ) : while ( $the_query->have_posts() ) : ?> <?php $the_query->the_post(); $id = get_the_ID(); ?> … Read more

PHP – Loop custom post type categories within jQuery Tabs

You can fire query only by ‘meta_key’=> ‘selsubcat’ without meta_value `and you will get all subcategories. Then you should loop outside you tab with some increment(maybe a name of category or numeric id) something like this: <?php foreach( $posts as $post ): setup_postdata( $post ); ?> <div id=”tabs-<?php the_ID(); ?>”> <table id=”table-<?php the_ID(); ?>” class=”display” … Read more