Forum Replies Created

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter ken78

    (@ken78)

    Solved my own issue thanks to some help on the main feedback form here: https://ww.wp.xz.cn/support/topic/how-to-disable-automated-wp-core-fetchpriorityhigh-application/#post-18464473

    I was utilizing the following function hook for Generate Blocks to sort my posts by a custom meta date field:

    //DATE type custom field value
    add_filter( 'generateblocks_query_loop_args', function( $query_args, $attributes ) {

    // apply filter if loop has class: order-by-end-date
    if ( ! is_admin() && ! empty( $attributes['className'] ) && strpos( $attributes['className'], 'order-by-end-date' ) !== false ) {

    $query_args = array_merge( $query_args, array(
    'meta_key' => 'end_date',
    'meta_type' => 'DATE',
    'orderby' => 'meta_value',
    'order' => 'ASC',
    ));
    }
    return $query_args;
    }, 10, 2 );

    Due to the way it operates, it seems to keep the fetchpriority=high attribute that was applied by WP Core even after having another function run at priority level 99 to remove this attribute.

    The following is my final code that removes the fetchpriority being added by WP Core, while still preserving the functionality of the meta date post order:

    //DATE type custom field value
    add_filter( 'generateblocks_query_loop_args', function( $query_args, $attributes ) {

    // apply filter if loop has class: order-by-end-date
    if ( ! is_admin() && ! empty( $attributes['className'] ) && strpos( $attributes['className'], 'order-by-end-date' ) !== false ) {

    $query_args = array_merge( $query_args, array(
    'meta_key' => 'end_date',
    'meta_type' => 'DATE',
    'orderby' => 'meta_value',
    'order' => 'ASC',
    ));
    }
    return $query_args;
    }, 10, 2 );

    add_filter( 'wp_get_loading_optimization_attributes', function( $attributes, $context ) {
    if ( isset( $attributes['fetchpriority'] ) && $attributes['fetchpriority'] === 'high' ) {
    unset( $attributes['fetchpriority'] );
    }
    return $attributes;
    }, 11, 2 );

    Hopefully this helps someone else out that is scratching their head on why they cannot get WP Core fetchpriority=high attributes removed from images pulled by Generateblocks queries.

    If you are ordering your queries, place the unset function call at the end of your ordering functioning and set the priority to 11 (or 1 lower than whatever your priority is for your order function). This will fix the issue.

    Thank you.

    • This reply was modified 1 year ago by ken78.
    Thread Starter ken78

    (@ken78)

    @yashjawale

    add_filter( 'wp_get_loading_optimization_attributes', function( $attributes, $context ) {
    if ( isset( $attributes['fetchpriority'] ) && $attributes['fetchpriority'] === 'high' ) {
    unset( $attributes['fetchpriority'] );
    }
    return $attributes;
    }, 10, 2 );

    Thank you for your assistance, I was able to fix the issue by modifying the priority of your code slightly and having it execute at the proper time.

    I discovered I had a conflicting code that was merging attributes after they were performed and I suspect after the fetchpriority=high attribute was already applied by WP Core. Even when running the your code separately at priority level 99, it was not removing the fetchpriority=high attribute from those images.

    The conflicting code I was using was a function hook for another plugin called Generate Blocks for ordering a separate query loop by a custom meta date field. This code is as follows:

    //DATE type custom field value
    add_filter( 'generateblocks_query_loop_args', function( $query_args, $attributes ) {

    // apply filter if loop has class: order-by-end-date
    if ( ! is_admin() && ! empty( $attributes['className'] ) && strpos( $attributes['className'], 'order-by-end-date' ) !== false ) {

    $query_args = array_merge( $query_args, array(
    'meta_key' => 'end_date',
    'meta_type' => 'DATE',
    'orderby' => 'meta_value',
    'order' => 'ASC',
    ));
    }
    return $query_args;
    }, 10, 2 );

    In order to fix my issue, all I had to do was add your add code to the end of this code and set priority to 11. The following is my final code that fixed my issue of removing the automated fetchpriority=high attribute whilst still allowing me to order the query by custom meta field date:

    //DATE type custom field value
    add_filter( 'generateblocks_query_loop_args', function( $query_args, $attributes ) {

    // apply filter if loop has class: order-by-end-date
    if ( ! is_admin() && ! empty( $attributes['className'] ) && strpos( $attributes['className'], 'order-by-end-date' ) !== false ) {

    $query_args = array_merge( $query_args, array(
    'meta_key' => 'end_date',
    'meta_type' => 'DATE',
    'orderby' => 'meta_value',
    'order' => 'ASC',
    ));
    }
    return $query_args;
    }, 10, 2 );

    add_filter( 'wp_get_loading_optimization_attributes', function( $attributes, $context ) {
    if ( isset( $attributes['fetchpriority'] ) && $attributes['fetchpriority'] === 'high' ) {
    unset( $attributes['fetchpriority'] );
    }
    return $attributes;
    }, 11, 2 );

    Thank you all for your assistance, I’m marking this issue resolved now.

Viewing 2 replies - 1 through 2 (of 2 total)