• I added some custom code to the plugin to allow for setting custom content instead of excerpts (in my case I wanted to use the meta_key ‘description’). Here is the hard coded code, was hoping you would add this in the next version, a lot of client always want to use custom meta fields for content, not excerpts. This is just broad POC code but you can get the jist from it.

    functions.php (update case ‘content’ with below)

                            //case 'content':

                                //$prefix            = PT_CV_PREFIX . 'field-content-';

                                //$field_setting     = PT_CV_Functions::settings_values_by_prefix( $prefix );

                                //if ( $field_setting[ 'show' ] == 'excerpt' ) {

                                //  $field_setting = array_merge( $field_setting, PT_CV_Functions::settings_values_by_prefix( PT_CV_PREFIX . 'field-excerpt-' ) );

                                //}

                                //$dargs[ 'field-settings' ][ $field ] = apply_filters( PT_CV_PREFIX_ . 'field_content_setting_values', $field_setting, $prefix );

                                //break;

                            //START GET DESCRIPTION INSTEAD OF EXCERPT CODE
                            case 'content':

                                $prefix = PT_CV_PREFIX . 'field-content-';

                                $field_setting = PT_CV_Functions::settings_values_by_prefix($prefix);

                                // Fetch the 'description' field instead of the excerpt

                                $post_id = get_the_ID();

                                $description = get_post_meta($post_id, 'description', true); // Replace 'description' with the correct meta key

                                //error_log("Post ID: $post_id, Description: $description");

                                if (!empty($description)) {

                                    $field_setting['content'] = $description; // Set description as the content

                                } else {

                                    $field_setting['content'] = get_the_content(); // Fallback to the content

                                }

                                $dargs['field-settings'][$field] = apply_filters(

                                    PT_CV_PREFIX_ . 'field_content_setting_values',

                                    $field_setting,

                                    $prefix

                                );

                                break;

                            //END GET DESCRIPTION INSTEAD OF EXCERPT CODE

    Update html.php (update _field_content function to below)

                    //START GET DESCRIPTION INSTEAD OF EXCERPT CODE - SEAN DAVIS 12-18-24

                    case 'excerpt':

                        $length = (int) $fargs['content']['length'];

                        $readmore_btn = '';

                        $show_dots = apply_filters(PT_CV_PREFIX_ . 'field_excerpt_dots', 1, $fargs);

                        $tail = $show_dots ? ' ...' : '';

                        // Read more button

                        if (apply_filters(PT_CV_PREFIX_ . 'field_content_readmore_enable', 1, $fargs['content'])) {

                            $readmore_btn = self::_field_readmore($post, $fargs, 'content');

                            $tail .= apply_filters(PT_CV_PREFIX_ . 'field_content_readmore_seperated', '<br/>', $fargs);

                        }

                        // Fetch the description field

                        $description = get_post_meta($post->ID, 'description', true); // Replace 'description' with the correct meta key

                        if (!empty($description)) {

                            // Use the description field if available

                            $excerpt = apply_filters(PT_CV_PREFIX_ . 'field_content_description', $description, $fargs, $post);

                        } else {

                            // Fallback to default content

                            $full_excerpt = apply_filters(PT_CV_PREFIX_ . 'field_content_excerpt', get_the_content(''), $fargs, $post);

                            if (apply_filters(PT_CV_PREFIX_ . 'trim_excerpt', true)) {

                                $excerpt = PT_CV_Functions::cv_trim_words($full_excerpt, $length);

                            } else {

                                $excerpt = $full_excerpt;

                            }

                        }

                        // Append readmore button

                        $content = apply_filters(PT_CV_PREFIX_ . 'excerpt_html', ($show_dots ? rtrim($excerpt, '.') : $excerpt) . $tail, $post) . $readmore_btn;

                        break;

                    //END GET DESCRIPTION INSTEAD OF EXCERPT CODE - SEAN DAVIS 12-18-24


    I know there’s a couple of other things that need to be done like the settings elements to select the custom meta vs except or full content but I’ll leave that to you if you find it valuable.

    The page I need help with: [log in to see the link]

Viewing 1 replies (of 1 total)
  • Plugin Author Content Views

    (@pt-guy)

    Hi @imseandavis,

    Thank you for sharing your code.
    We appreciate it.

    It is possible to show content from meta key using custom code with add_filter.
    This code is available to Pro users.

    If you need further information, please let us know.
    Best regards,

Viewing 1 replies (of 1 total)

The topic ‘Add Custom Content Field’ is closed to new replies.