the answer for all question about Oxygen Builder plugin and WordPress

Hello everybody,


Hello everybody,

I think that I am very close to fixing the “Repeaters for CPT taxonomy terms” problem and with a tiny bit of help we can solve this issue for the benefit of all interested.

My desire is to always offer the client the freedom of modification without my assistance and a lot of times I have found this to be hindered by the missing capabilities.

One small example which is featured here is the following:

We want to build a CPT with a taxonomy and have the url structure looking like this

For main archive page
mysite.com/books

For Taxonomy term archive page
mysite.com/books/topic

For single post
mysite.com/books/topic/thebookiwanttotelleveryoneabout

Also, we would like the end client to be able to add books or topics without our help. Each topic has a title, a description, a featured image, and other ACF fields.

What to do?

1 Create a CTP called “books” (set display front:false)
2 Create a Taxonomy called “topic” assigned to books
3 Create redirections in CTP UI for books and topics (needs separate tutorial)
4 Create the ACF fields for the Taxonomy term (an image called “topic_image” and a text field called “topic_excerpt”)
5 Populate the fields in each taxonomy term (title, description, image, extra text field- in my case)
6 Populate a few posts from the CPT and assign taxonomies to them
7 Add the code below using a script loader like Code Snippets
8 Create a PAGE for the main CTP display
(this takes care of the page mysite.com/books and offers you flexibility to do whatever you want on that page)
9 Create a repeater on that page. In query, select manual and add this code “post_type=taxonomy_terms_list”. Build your repeater “like normal”. This repeater displays the TAXONOMY TERMS not the CPT POSTS, that is simple, it can be done with a repeater set to the CTP.
10 Create a template and assign it to the archive of the taxonomy
(this takes care of the page mysite.com/books/topic and allows you to create an unlimited number of pages with only one template)
11 In the above template use the “default” query for repeater, and it should bring in all the posts corresponding to the displayed taxonomy
12 Create a single post template and assign it for the single post of your CPT (not for taxonomy)

I have used Gagan S Goraya code for the repeater, code found in this group, and managed to make it work for Title and Description but I am missing two things
1. How to add the ACF image
2. How to add any other ACF fields

The code:
get(‘post_type’) ) {

// And obviously, the $posts is going to be empty, lets ensure that its an empty array and not null
$posts = array();

// Lets populate it with the data that we want i.e., the terms for any arbitrary taxonomy

// get terms for any taxonomy
$terms = get_terms(
array(
‘taxonomy’ => ‘topic’,
‘type’ => ‘book’
)
);

foreach( $terms as $term ) {
$acf_url_img = get_field(‘topic_image’, $term->taxonomy . ‘_’ . $term->term_id );
$acf_url_img = (!empty ($acf_url_img[‘url’])?$acf_url_img[‘url’]:false);
$acf_excerpt_text = get_field(‘topic_excerpt’, $term->taxonomy . ‘_’ . $term->term_id );
$posts[] = (object) array(
‘post_title’ => $term->name,
‘post_name’ => $term->slug,
‘post_content’ => $term->description,
‘featured_image’ => $acf_url_img,
‘post_excerpt’ => $acf_excerpt_text
) ;
}
}

return $posts;
}

add_filter(‘posts_results’, ‘gsg_override_posts_results’, 10, 2);

Can anyone help with correcting the code above in order to be able to display the image assigned to the taxonomy?
How can other ACF fields assigned to the taxonomy terms be displayed in the repeater?




Source

1 Comment
  1. Alexandru Radulescu says

    Bump

Leave A Reply

Your email address will not be published.

Oxyrealm Docs