Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added option to display a custom meta field instead of post content #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions classes/class-post-content-shortcodes.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,9 @@ private function _setup_defaults() {
'link_image' => false,
// Whether to ignore password-protected posts in post list
'ignore_protected' => false,
/* Added by Tom */
// A custom meta field to display instead of post content
'custom_field' => '',
);
/**
* If this site is using the WP Views plugin, add support for a
Expand Down Expand Up @@ -553,6 +556,10 @@ public function post_content( $atts=array() ) {
$content = empty( $p->post_excerpt ) ? $p->post_content : $p->post_excerpt;
}

if ( $atts['custom_field'] && $atts['custom_field'] !== '' ) {
$content = empty( get_post_meta($p->ID, $atts['custom_field'], true) ) ? '' : get_post_meta($p->ID, $atts['custom_field'], true);
}

if ( intval( $excerpt_length ) && intval( $excerpt_length ) < str_word_count( $content ) ) {
$content = explode( ' ', $content );
$content = implode( ' ', array_slice( $content, 0, ( intval( $excerpt_length ) - 1 ) ) );
Expand Down Expand Up @@ -718,9 +725,9 @@ public function post_list( $atts=array() ) {
}
}

$excluded_tax = apply_filters( 'post-content-shortcodes-excluded-taxonomies', array(
'csb_visibility',
'csb_clone',
$excluded_tax = apply_filters( 'post-content-shortcodes-excluded-taxonomies', array(
'csb_visibility',
'csb_clone',
) );

foreach ( $args as $k => $v ) {
Expand Down