get posts - get_post Question

admin2025-06-02  1

We have a custom post that displays a main post and several child posts. The main parent post displays a table with a summery of specs for the product. at the bottom of the table we have a link to a child page that displays the full specs page. This page uses a template: page-specs.php. This was once working but no longer working. The page links to the current parent page.

    function get_full_stats_page($post_id) {
        $args  = array('post_parent' => $post_id, 'post_type' => 'reviews', 'meta_key' => '_wp_page_template', 'meta_value' => 'page-specs.php', 'posts_per_page' => 1);
        $posts = get_posts( $args );

        if(isset($posts[0])) 
            return get_permalink($posts[0]->ID);
        return false;
    }


/*
 * Custom shortcode to display specs table
 * This sidebar is used to display specs table of current post and also finds a link for full specifications page.
 [reviews-specs-table]
 * Author - Preetam
 */


add_shortcode('reviews-specs-table', 'reviews_specs_table_handler');

function reviews_specs_table_handler() {
    $full_specs = get_full_stats_page($post->ID);
     //$full_specs = get_specs_link($post->ID);

$manufacturer = array_pop(get_the_terms($post->ID,'manufacturers'))->name;
$specs = array(
    'price' => 'Price',
    'technology' => 'Technology',
    'native_resolution' => 'Native Resolution',
    'brightness' => 'Brightness (Manufacturer Claim)',
    'contrast' => 'Contrast',
    'zoom_lens_ratio' => 'Zoom Lens Ratio',
    'lens_shift' => 'Lens Shift',
    'lamp_life' => 'Lamp Life',
    'weight' => 'Weight',
    'warranty' => 'Warranty'
);

$table = "";
$table .= '<table id="specs-preview" class="table table-responsive table-striped table-bordered specList" cellpadding="5" cellspacing="2">';
    $table .= '<thead>';
        $table .= '<tr>';
            $table .= '<th class="sec-header" colspan="2">' . $manufacturer . " " . get_field('model_number') . ' Specs</th>';
        $table .= '</tr>';
$table .= '</thead>';

$table .= '<tbody>';

foreach ( $specs as $spec => $title )
{
        $field = get_field( $spec );
        $table .=  '<tr>';
                $table .=  '<td class="title">' . $title . '</td>';
                $table .=  '<td>' . filter_pr_review( $spec, get_field($spec) ) . '</td>';
        $table .=  '</tr>';
}

$table .= '</tbody>';

$table .= '<tfoot>';
    $table .= '<tr>';
            if($full_specs){
                $table .= '<td colspan="2"><a href="' . get_permalink($full_specs->ID) . '">View Full Specifications Here &gt;&gt;</a></td>';
                $table .= '<td colspan="2"></td>';
            }else{
                $table .= '<td colspan="2">&nbsp;</td>';
            }
    $table .= '</tr>';
$table .= '</tfoot>';

$table .= '</table>';

return $table;
}
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1748854588a314276.html

最新回复(0)