Get custom field from a post in rank-math.php

#522054
  • Resolved Quentin
    Rank Math free

    Hi,

    I have this function in rank-math.php to change the seo title on some of my posts :

    
    /**
     * Filter to change the page title.
     * 
     * @param string $title
     */
    add_filter( 'rank_math/frontend/title', function( $title ) {
    	$categories = array_map( function ( $category ) {
    		return $category->slug;
    	}, get_the_category() );
    
    	if (count($categories) > 0) {
    		// Add content to page title for specific post categories
    		if ( in_array( 'temoignage', $categories ) ) { 
    
    			$post = get_post();
    
    			// Cannot find function to get a custom field ?
    			$job = RankMath\Post::get_meta('job', $post->ID, '');
    			
    			$text = 'Témoignage %title% '.$job.' %sep% %sitename%';
    			
    			$title = RankMath\Helper::replace_vars($text , $post );
    			
    		}
    	}
    	return $title;
    });
    

    I have a custom field “job” in all of these posts, is it possible to access it in the code above ? I cannot seem to find any documentation on all of the available functions for “RankMath\Helper”, “RankMath\Post”, etc.

    Thank you very much for your time

Viewing 2 replies - 1 through 2 (of 2 total)
  • Ok, found the solution on another post, I had to change this in the code to get my custom field “job” :

    
    $text = 'Témoignage %title% %customfield(job)% %sep% %sitename%';
    

    However I maintain a documentation with all the available php functions and possible parameters would be very useful. Or maybe I missed it ?

    Thank you again for your time and consideration.

    Best regards

    Hello,

    Glad that everything has been sorted out.

    Please feel free to reach out to us again in case you need any other assistance.

    We are here to help.

    Thank you.

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

The ticket ‘Get custom field from a post in rank-math.php’ is closed to new replies.