<?php
/*
https://wordpress.stackexchange.com/questions/188138/modify-wp-title-for-custom-post-types-using-custom-fields-data
*/
function custom_post_title( $title_parts ) {
	global $opt_themes, $post;
	if( $opt_themes['single_appname'] ){
    if ( is_singular( 'post' ) ) {
        $the_title	= get_the_title();
		$app_name 	= get_post_meta( $post->ID, 'wp_title_GP', true);
		$app_versi 	= get_post_meta( $post->ID, 'wp_version_GP', true );
		if(get_post_meta( $post->ID, 'wp_mods', true )){
		$app_mod 	= '('.trim(strip_tags(ucwords(get_post_meta( $post->ID, 'wp_mods', true )))).')';
		} else {
		$app_mod 	= '';
		}
		$t_mod_apk 	= $opt_themes['text_18']; 
        $title_parts['title'] = $app_name.' '.$t_mod_apk.' v'.$app_versi.' '.$app_mod;
        $title_parts['title'] = esc_html( $title_parts['title'] );
        return $title_parts;
    } else {
        return $title_parts;
    }
	} else {
        return $title_parts;
    }
}

//add_filter( 'document_title_parts', 'custom_post_title' );

 
function custom_dw_post_title( $title_parts ) {
	global $opt_themes, $post, $wp_query;
	if( $opt_themes['single_appname'] ){
    if ( isset( $wp_query->query_vars['download'] ) ) {	
        $the_title	= get_the_title();
		$app_name 	= get_post_meta( $post->ID, 'wp_title_GP', true);
		$app_versi 	= get_post_meta( $post->ID, 'wp_version_GP', true );
		if(get_post_meta( $post->ID, 'wp_mods', true )){
		$app_mod 	= '('.trim(strip_tags(ucwords(get_post_meta( $post->ID, 'wp_mods', true )))).')';
		} else {
		$app_mod 	= '';
		}
		$t_mod_apk 	= $opt_themes['text_18']; 
		$t_download	= $opt_themes['text_19']; 
        $title_parts['title'] = $t_download.' '.$app_name.' '.$t_mod_apk.' v'.$app_versi.' '.$app_mod;
        $title_parts['title'] = esc_html( $title_parts['title'] );
        return $title_parts;
    } else {
        return $title_parts;
    }
	} else {
        return $title_parts;
    }
}

//add_filter( 'document_title_parts', 'custom_dw_post_title' );
