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

    (@bappidgreat)

    Hello Faisal Habib

    You can’t cache php code. PHP is used to cache output of an operation.

    i want to cache these files

    mywebsite.com/embed/212

    This is not a file but a rewritten url. I am not sure if I am following you properly. Would you please explain again? Maybe rephrase?

    Have a good day!

    Cheers
    Ash

    Thread Starter Faisal Habib

    (@floost)

    Thanx sir for reply,
    here is my url https://dramaxima.com/embed/1834

    1834 is post id here

    function td_embed_generate(){
    
        if( is_admin() ) return;
    
        $current_url = esc_url( home_url( add_query_arg( NULL, NULL ) ) );
    
        if ( preg_match( "#^http.*\/embed\/\d{1,}#i", $current_url ) ) {
    
            $array_id = explode( '/', $current_url );
    
            $post_id = end( $array_id );
    
            if( ! is_numeric( $post_id ) ) return;
    
            $args = array(
    
                'p'              => $post_id,
    
                'posts_per_page' => 1
    
            );
    
            $embed = get_posts( $args );
    
            if ( ! isset( $embed[0]->ID ) ) return;

    and this is code to get custom field from posts (using post id)

    i want to cache these embed urls so every time they don’t fetch code from functions.php

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How can i cache php code’ is closed to new replies.