Some modifications on archive page

Hi, i’m trying to customize the archive page for Sparkling Theme, but i can’t go further.

First of all, i copy the archive.php to my child theme directory,

so i change the get_template_part( 'content', get_post_format() );

to get_template_part( 'content', get_post_type() );

And create a file called content-posttypename.php and write this:

 * @package sparkling

<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<div class="post-inner-content">
<div class="entry-content">
<a href="<?php the_permalink(); ?>">
<h5><?php the_title(); ?></h5>
<p><strong><?php echo do_shortcode('[ct id="_ct_text_5436ea04987f4" property="title | description | value"]'); ?> dias:</strong> <?php echo do_shortcode('[ct id="_ct_text_543b238b38a41" property="title | description | value"]'); ?></p>

This works fine. There is some wrong with my content-posttypename.php code?

So, i can show posts, but now what i need is organize my content. I have a custom field called city and other called duration, i want to organize my posts in that order:


  • duration 01
  • duration 02
  • duration 03
  • duration 01
  • duration 02
  • duration 03
  • duration 01
  • duration 02
  • duration 03

Somebody knows how to write the loop for this case? I really appreciate your attention. I tryed a lot of the Codex exemples but with no lucky.

To be honest, I have absolutely no idea how this can be done via WordPress loop. Maybe you should create some categories tags or other taxonomies to be able to call them via loop but I have never seen example where posts are called based on custom fields.

Since this is not general WordPress support you might want to ask your question on or search for answer there as others migth have the same problem as you.

Sorry about that.

Thank you for your time Aigars.

I got on StackExchange (good source, definitely on my bookmarks) and read about Wp_query and a lot of diffrent types of implementation. I find a similar issue of my, the answer is in this code:

function alter_order_wpse_103181($order,$qry) {
  $order = explode(',',$order);
  $order = implode( ' ASC,',$order);
  return $order;

$q = new WP_Query();
$q->query( array(
  'post_type' => 'movies', 
  'distribution' => 'companyA', 
  'meta_key' => 'year',
  'orderby' => 'meta_value_num title',  
  'order' => 'ASC', 
  'posts_per_page' => -1, 
  'post_status' => 'publish',

I think i understand the code but i don’t know where to put. Is silly but how to implement this code on my child-theme? The ‘function’ part belongs to functions.php? And the rest of the code goes on my archive.php or on my content-posttypename.php? If is on my ‘content-’, where i put the code?

I’m sorry for the bad english =/

Thank you for amazing job on Sparkling theme and this inspiring support.

Today i made good progress on my child-theme, functions are awesome!

I left behind 13 installed plugins :smiley:

But i can’t organize these posttypes properly.

I tried to put the function part on the functions.php, put the query part on my archive.php and i got a big error message.

What i need is exactly like this:

But here:

Does anybody know how to write this loop?


Not exaaactly huahuaha wp-<3

Theres some really crazy WP_Query going on, at least from one I can see in error message.

Would you mind sharing the entire code block, so I can see what is going on there.

I can’t promise you solution as this would take a lot of time debugging and I don’t have time for that but maybe I will see something right away.

Sorry about that.

Hi Aigars,

men, i work a lot on this issue. At the end i don’t even use the archieve template hahaha

I read more about templates hierarchy on wp, so i decide to use taxonomy-custonposttype.php then i change my organization structure based on taxonomy and custom fields. So i grouped my single posts by taxonomys and order by custom field. The result don’t looks like the exemples i read about, but i like it.

My code template-posttypename.php code is:

<?php get_header(); $term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) ); ?>
<h2><?php echo apply_filters( 'the_title', $term->name ); ?></h2>
$cidades = get_terms( 'inicio', array(
    'orderby'    => 'title',
	'order' => 'ASC',
    'hide_empty' => true,
) );
foreach( $cidades as $cidade ) {
$regiao_query = new WP_Query( array(
  'post_type' => 'individual',
  'post_status' => 'publish',
  'inicio' => $cidade->slug,
  'posts_per_page' => -1,
  'orderby' => 'meta_value_num',
  'meta_key' => 'ct_dias_text_adfa',
  'order' => 'ASC',
  'hide_empty' => true,
  'tax_query' => array(
      'taxonomy' => 'regiao',
      'field' => 'slug',
      'terms'    => $term,
) );		
		 while ( $regiao_query->have_posts() ) : $regiao_query->the_post();

			get_template_part( 'content', get_post_type() ); 

		endwhile; wp_reset_postdata();

And is alive!