0

I have a custom taxonomy called projects that has a custom post type called apartments, both have acf custom fields.

I want to bring the taxonomy created projects with their acf fields on a certain page, example project 1, project 2.

I have created taxonomy-projects_apartments.php and used it as a template, for a page called projects.

$args = array(
    'taxonomy'     => 'projects',
    'orderby'      => $orderby,
    'show_count'   => $show_count,
    'pad_counts'   => $pad_counts,
    'hierarchical' => $hierarchical,
    'title_li'     => $title
);

wp_list_categories( $args ); 

This only brings the names, project 1 and project 2. On the single project page I use:

$queried_object = get_queried_object();
$taxonomy = $queried_object->taxonomy;
$term_id = $queried_object->term_id;

// load content for this taxonomy term
$custom_field = get_field('insert_new_project', 'projects' . '_' . $term_id);

to bring custom fields, and it works.

But queried objects brings the current page object, and does not work in the way I needed it to.

Any suggestions ?

  • What's the stored data in %term_meta table against the $term_id in database? Sort 'em there first, then try the ACF. It'll make the process less buggy. – Mayeenul Islam Jun 24 '18 at 14:59
  • OK, wait... So what exactly are you trying to achieve? What custom fields are there? What objects are there assigned for? And where do you want to display what...? – Krzysiek Dróżdż Jun 24 '18 at 21:05
  • Updated code: $newargs = array( 'post_type' => 'apartamente', 'tax_query' => array( array( 'taxonomy' => 'projects', 'field' => 'slug', ) ) ); $the_query2 = new WP_Query( $newargs ); – Marius Jun 25 '18 at 13:09
0

Updated code:

                                                                                                       $newargs = array(
        'post_type' => 'apartments',
        'tax_query' => array(
            array(
                'taxonomy' => 'projects',
                'field' => 'slug',
            )
        )
    );

    $the_query = new WP_Query( $newargs );



<?php if ( $the_query->have_posts() ) : ?>

 //The query returns 0, if I use a taxonomy, for post types it works, and I can bring all ACF fields to that post. But I want also want taxonomy acf fields here.
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>

//Custom field that Is inserted into apartments custom post type

 <?php while ( have_rows( 'assign_apartment_project') ) : the_row(); ?>


<?php endwhile; ?>
<?php endwhile; ?>
<?php wp_reset_postdata(); ?>

<?php endif; ?>       

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.