• Resolved Gerson Lacdao

    (@gslweb)


    I have 2 questions:

    1. Does the query loop block process shortcodes? I created a query loop to display a custom post type and inserted a shortcode in it but it doesn’t display the shortcode value. I know it’s working because I use it in the single post template and it displays it just fine, but not inside a query loop.
    2. Is there a filter I can use to modify the date format that’s fetched using dynamic data? It’s set by another plugin (not ACF) and it’s only saved using Y-m-d but I want to display it using F d, Y format. I initially thought of using a shortcode but no shortcodes seem to be processed inside the query loop. What would you suggest is the best way to modify the date format in this scenario?

    Thanks!

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Support fernandoazarcon2

    (@fernandoazarcon2)

    Hi @gslweb,

    1. Inherently, shortcodes work on Query Loops. What doesn’t work are functions like get_the_ID(). This is a WordPress core issue though. You’ll experience the same thing using the WordPress Query Loop Block. What you can use is a filter called render_block.
    2. There’s a generateblocks_dynamic_content_output filter you can use. You can find the filter here.
    Thread Starter Gerson Lacdao

    (@gslweb)

    Would you be able to provide simple examples on how to use each of these?

    Plugin Support fernandoazarcon2

    (@fernandoazarcon2)

    Here’s a sample code for a Headline Block with class convert-to-fdy

    add_filter('generateblocks_dynamic_content_output', function($content, $attributes, $block){
    	if ( ! empty( $attributes['className'] ) && strpos( $attributes['className'], 'convert-to-fdy' ) !== false ) {
    		$timestamp = strtotime($content);
    		$my_date = sprintf(
    		'<time datetime="%1$s">%2$s</time>',
    		date('c', $timestamp),
    		date('l F d, Y', $timestamp) );
    		return $my_date;
    	}
    	return $content;
    }, 10, 3);
    Thread Starter Gerson Lacdao

    (@gslweb)

    Thanks! In case anyone needs it, here’s what I was able to come up with for #1:

    add_filter( 'render_block', function( $block_content, $block ) {
        if ( !is_admin() && ! empty( $block['attrs']['className'] ) && strpos( $block['attrs']['className'], 'user-class-here' ) !== false ) {
    		$hosts = get_field('acf_user_field_id');
            if( $hosts ) {
                $hosts_list = '<p>';
                foreach( $hosts as $host ) {
                    $hosts_list .= $host['display_name'];
                }
                $hosts_list .= '</p>';
                $block_content .= $hosts_list;
            }
    		
        }
    
        return $block_content;
    }, 10, 2 );
    Plugin Support David

    (@diggeddy)

    Hi there,

    you may want to consider the render_block_{$this->name} hook:

    https://developer.www.ads-software.com/reference/hooks/render_block_this-name/

    it will limit your callback to just the specified block, instead of every block.

    Plugin Support fernandoazarcon2

    (@fernandoazarcon2)

    Hi there! We haven’t heard back from you for a while now so we’re going to go ahead and set this topic as resolved. Feel free to open a new topic if you need assistance with anything else.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Shortcodes and Processing Dynamic Data’ is closed to new replies.