Support

Account

Home Forums ACF PRO Using post information in a widget

Helping

Using post information in a widget

  • I’m looking to build a widget which will render out infomation relevant to the current post and the last 10 articles which share the same relationship, but I’m struggling in two areas:

    My widget code doesn’t appear to be able to retrieve the post relationship, the same code in my single.php running in the post works fine. At best I can pull the relationship out in the post body and register it as a global – there has to be a better way?

    I can’t find a way to easily fetch other posts which are also related to the same post.

    I’ve purchased ACF pro as I had interpreted widget interaction as an ACF 5 requirement, but upon further inspection the widget functionality refers to targeting widgets in the back end.

    Any pointers?

  • Hi @pixeldynamo

    Within your widget code you must find a way to obtain the current $post ID. Then you can get ACF to return the correct data by using the second parameter of teh get_field function.
    http://www.advancedcustomfields.com/resources/how-to-get-values-from-another-page/

    Most likely you can find the $post with this:

    
    global $post;
    $post_id = $post->ID;
    

    Good luck

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

The topic ‘Using post information in a widget’ is closed to new replies.