Support

Account

Home Forums Front-end Issues add_filter

Unread

add_filter

  • Hello, I’m trying to figure out how to use ACF and add_filter. I have a function where for a page, I can add a code snippet with an ID, and it pulls in all data from that ID (code below).

    Before we started with ACF, it worked by pulling in the_post with add_filter and everything got pulled across. It causes and issue with breadcrumbs though, where the breadcrumbs are related to original post. Eg:

    HOME / COURSE / COURSE #1 – this is original course with data
    HOME / COURSE / COURSE #7 – this has ID of course #1 in main WP editor field and pulls data across from #1.

    Originally I did:

    add_filter('the_post', 'ghost_blog', $priority=1);

    But since it overwrote my breadcrumbs, I changed it to:

    add_filter('the_content', 'ghost_blog', $priority=1);

    The problem is that it doesn’t pull across all ACF data. So I was wondering if there was some ACF related filter I can hook into, to get chance to pull all info across.

    Thanks!

    	global $wpdb;
    	global $post;
    	
    	$content = $post->post_content;
    	
    	$search = "@\[ghost=(\d+)\]@i";
    	if (preg_match_all($search, $content, $matches, PREG_SET_ORDER)) 
    	{
    		foreach ($matches as $match) 
    		{
    			$ghost_id = trim($match[1]);
    			$inner_query = new WP_Query("post_type=page&page_id=$ghost_id");
    			if( $inner_query->have_posts() )
    			{
    				$inner_query->the_post();
    			}
    		}
    	}
    }
    add_filter('the_post', 'ghost_blog', $priority=1);
Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.