admin管理员组

文章数量:1124075

I've introduced a new post type in WordPress named "car" where I showcase the specifications of various cars. I've extensively utilized Advanced Custom Fields (ACF) with numerous fields for all the specifications and details.

In the page-price.php template: I've additionally created a new group field for the car prices on a page where I list all the cars and set their prices. Now, I aim to input the identifier for each car in that list to display the prices on the "car" post type page.

My field names in page-price.php:

pr-price is brand loop
pr-p-brand is brand name
pr-p-list is car loop
pr-p-i-id id num field for id page
pr-p-i-co is num field for car price

output in price list page:

BMW:
1- BMW X4   $12.0000.000
2- BMW X6   $10.0000.000
Benz:
1- benz G class  $8.0000.000
2- benz S class  $9.0000.000

My objective is to manage and update price changes for each car on a single page, ensuring that the modifications reflect across all different car specification pages. I'm also looking to avoid the hassle of individually editing all posts related to the 200 cars.

1- Will this potentially lead to slow loading of the car specification pages?

2- How can I display the price of each car on the single post page of each car?

<div class="car-price">
    <?php
    $current_car_id = get_the_ID(); // this car id

    if (have_rows('pr-price')):
        while (have_rows('pr-price')): the_row();
            if (have_rows('pr-p-list')) :
                while (have_rows('pr-p-list')): the_row();
                    $car_id_in_price_table = get_sub_field('pr-p-i-id');
                    if ($car_id_in_price_table == $current_car_id) :
                        // show price of car
                        echo get_sub_field('pr-p-i-co');
                    endif;
                endwhile;
            endif;
        endwhile;
    endif;
    ?>
</div>

I've used this code in my single-car.php, but it's not functioning. How should I proceed to resolve this?

本文标签: loopDisplaying Car Prices from Page Listings on Each Post Car Pages (Post Type) Using ACF