bobbingwide / oik-fields

Field formatting for custom post type (CPT) meta data, plus [bw_field], [bw_fields], [bw_new] and [bw_related] shortcodes
https://www.oik-plugins.com/oik-plugins/oik-fields-custom-post-type-field-apis/
1 stars 0 forks source link

Improve [bw_fields] to use within a `core/query-loop` block #34

Open bobbingwide opened 3 years ago

bobbingwide commented 3 years ago

While investigating bobbingwide/fizzie/issues/28 I developed a fix for using the [bw_fields] shortcode to display the fields for the current post in an archive display. If the id attribute value passed to the shortcode is . then the current post ID is used. This overrides the is_single() checking that I'd implemented 5 years ago.

The code change was to add the last 3 lines in this extract:

function bw_metadata( $atts=null, $content=null, $tag=null ) {
    if ( !oik_is_shortcode_expansion_necessary() ) {
        return "Not today thank you.";
    }
  $post_id = bw_array_get( $atts, "id", null );
    if ( '.' === $post_id ) {
        $post_id = bw_current_post_id();
    }

I then found an alternative solution; use [bw_field] instead of [bw_fields]. I could use this because I did not need the field's prefix.

Requirement

Consider adding this as a possible solution to the second @TODO for the bw_metadata function

@TODO decide best way to deal with nested usage of this shortcode or multiple usage of this shortcode
 * when the post we're trying to process is different from the main post. 
 * This happens when we are combining information from multiple posts into one output. 
 * Current solution is to not produce anything, not even 'Not single'