AddFont('loraregular', '', 'loraregular.php'); $html2pdf->AddFont('margembold', '', 'margembold.php'); $html2pdf->AddFont('margemlight', '', 'margemlight.php'); $html2pdf->AddFont('margemregular', '', 'margemregular.php'); $html2pdf->setDefaultFont('margemregular'); // Use global $post object to get the post ID //global $post; //$post_id = $post->ID; $postIdUrl = $_GET['post_id']; if (!$postIdUrl) return; $post_id = url_to_postid($postIdUrl); if (!$post_id) return; // Check if $post_id is a valid post ID if ($post_id > 0 && get_post_status($post_id)) { // Fetch the post object $post = get_post($post_id); // Check if $post is a valid object if ($post instanceof WP_Post) { // Get individual ACF fields $pageID = get_the_ID(); $post_title = get_the_title($post_id); $role = get_field('role', $post_id); $resume = get_field('resume', $post_id); $email = get_field('email', $post_id); $image_pdf = get_field('image_pdf', $post_id); $areas_practice = get_field('areas_practice', $post_id); $about = get_field('about', $post_id); $experience = get_field('experience', $post_id); $awards = get_field('awards_content', $post_id); $education = get_field('education', $post_id); $memberships = get_field('memberships', $post_id); $academy = get_field('academy', $post_id); $publications = get_field('publications', $post_id); $languages = get_field('languages', $post_id); $cols = array(); function format_content($html) { return str_replace('
  • ', '
  • ', $html); } if (!empty($areas_practice)) { $areas_content = '

    ' . get_field('areas_practice_title') . '

    '; array_push($cols, $areas_content); } if (!empty($about)) { $about_title = get_field('about_title'); $about_content = get_field('about'); // Use wpautop to add paragraphs $about_content_with_paragraphs = wpautop($about_content); // Apply additional styling and container $styled_about_content = '' . $about_content_with_paragraphs . ''; // Add
    before and after
    $styled_about_content = str_replace('
    ', '
    ', $styled_about_content); $styled_about_content = str_replace('
    ', '


    ', $styled_about_content); array_push($cols, '

    ' . $about_title . '

    ' . $styled_about_content); } if (!empty($experience)) { array_push($cols, '

    ' . get_field('experience_title') . '

    ' . $experience); } if (!empty($awards)) { array_push($cols, '

    ' . get_field('awards_title') . '

    ' . $awards); } if (!empty($education)) { array_push($cols, '

    ' . get_field('education_title') . '

    ' . $education); } if (!empty($memberships)) { array_push($cols, '

    ' . get_field('memberships_title') . '

    ' . $memberships); } if (!empty($academy)) { array_push($cols, '

    ' . get_field('academy_title') . '

    ' . $academy); } if (!empty($publications)) { $publications = ''; if (have_rows('publications', $pageID)) { while (have_rows('publications', $pageID)) { the_row(); $publication_title = get_sub_field('title'); $publication_url = get_sub_field('url'); $publication_download_url = get_sub_field('download_url'); if (filter_var($publication_url, FILTER_VALIDATE_URL)) { $publications .= '
  • ' . $publication_title . ' Read more
  • '; } else { $publications .= '
  • ' . $publication_title . '
  • '; } } $publications = '

    ' . get_field('publications_title') . '

    '; } else { $publications = get_field('publications', $post_id) ?: ''; } array_push($cols, $publications); } if (!empty($languages)) { array_push($cols, '

    ' . get_field('languages_title') . '

    ' . $languages); } $logo = 'https://websitecms.gcsc.com.mx/wp-content/themes/gonzalez-backend/img/logo-naming-blue.png'; // Check if other fields are set before using them $title = get_field('get_the_title', $post_id) ?: ''; $role = get_field('role', $post_id) ?: ''; $resume = get_field('resume', $post_id) ?: ''; $email = get_field('email', $post_id) ?: ''; $publications = get_field('publications', $post_id) ?: ''; $image_pdf = get_field('image_pdf', $post_id); $user_image = $image_pdf['url']; $html = '






    ' . $post_title . '

    ' . $role . '

    ' . $resume . '

    ' . $email . '

    ' . implode('', $cols) . '
    '; $html2pdf->writeHTML($html); $html2pdf->output(); } else { // Handle the case where $post is not a valid object echo "Error: Invalid post object."; } } else { $post_id = 23442; $post = get_post($post_id); if (is_object($post) && is_a($post, 'WP_Post')) { // Your existing code here } else { // Handle the case where $post_id is not a valid post ID echo "Error: Invalid post ID."; } echo "Error: Invalid post ID."; } ?>