Home Forums ACF PRO Getting Custom fields from 2 different pages to compare (ajax?) Reply To: Getting Custom fields from 2 different pages to compare (ajax?)

  • I found a code snippet from github that will help me create pages without actually creating them, here it is:

    // create fake page called "chat-room"
    // modify function and variable names with "ABCD" to whatever you like
    // modify variable $fakepage_ABCD_url to the fake URL you require
    function fakepage_ABCD_detect($posts){
        global $wp;
        global $wp_query;
        global $fakepage_ABCD_detect; // used to stop double loading
            $fakepage_ABCD_url = "chat-room"; // URL of the fake page
        if ( !$fakepage_ABCD_detect && (strtolower($wp->request) == $fakepage_ABCD_url || $wp->query_vars['page_id'] == $fakepage_ABCD_url) ) {
            // stop interferring with other $posts arrays on this page (only works if the sidebar is rendered *after* the main page)
            $fakepage_ABCD_detect = true;
            // create a fake virtual page
            $post = new stdClass;
            $post->post_author = 1;
            $post->post_name = $fakepage_ABCD_url;
            $post->guid = get_bloginfo('wpurl') . '/' . $fakepage_ABCD_url;
            $post->post_title = "Page Title";
            $post->post_content = fakepage_ABCD_render();
            $post->ID = -1;
            $post->post_type = 'page';
            $post->post_status = 'static';
            $post->comment_status = 'closed';
            $post->ping_status = 'open';
            $post->comment_count = 0;
            $post->post_date = current_time('mysql');
            $post->post_date_gmt = current_time('mysql', 1);
            // make wpQuery believe this is a real page too
            $wp_query->is_page = true;
            $wp_query->is_singular = true;
            $wp_query->is_home = false;
            $wp_query->is_archive = false;
            $wp_query->is_category = false;
        return $posts;
    function fakepage_ABCD_render(){
        return "My amazing pretend page :D";

    Please help me figure out how to change the url, title, and get the custom fields I want dynamically for 2 pages I choose.