• On some pages, we would like to make them as if it’s a product page, whereby the contentID is populated by a variable, in this case either customfieldID or post_ID.
    I’ve added it as an custom event, but I only found on how to populate that field with fixed values. I’d like to populate it with a variable, so content_ids = customfieldID, or post_ID, where that variable is taken from that page.

    Is that possible, and how can that be done?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Antonino Scarfì

    (@antoscarface)

    Hi,

    if you are a developer and you can play with PHP code, you can use a useful filter of plugin that gives you the ability to change the parameters inside an event.

    Here an example:

    
    add_filter( 'aepc_event_parameters', function( $params, $eventName ){
    	$params['content_ids'] = [ get_post_meta(get_the_ID(), 'customfieldID', true) ];
    	return $params;
    });
    

    This is just an example. Adapt it in your website.

    Thread Starter dantwah

    (@dantwah)

    Hi!

    Thanks for getting back! I do write som PhP so thanks for the snippet.

    I am not sure though the code you sent is working.

    I tried the filter but it is not actually changing anything..

    Also I see $eventName is not used? I tried setting this to ViewContent but it does not work?

    I guess changing get_post_meta(get_the_ID(), ‘customfieldID’, true) to “22” would at change the content_ids to 22 at all places? Right?

    Well OK, hope you can help!

    Thread Starter dantwah

    (@dantwah)

    Basically what I need to do is:

    Make the content_ids in this screen dynamic (of ViewContent type) http://prntscr.com/mgumas

    Plugin Author Antonino Scarfì

    (@antoscarface)

    Hi,

    I’m sorry, I forgot to mention two details, here the updated snippet example:

    
    add_filter( 'aepc_event_parameters', function( $params, $eventName ){
        if ($eventName === 'view_content') {
            $params['content_ids'] = [ 22 ];
        }
        return $params;
    }, 10, 2);
    

    The new details are:
    1. that 10, 2 as other parameters of add_filter, in order to accept the $eventName parameter;
    2. in $eventName there is the “underscored” version of the original event name, so ViewContent -> view_content, Purchase -> purchase, AddToCart -> add_to_cart, and so on.

    Then, I was able to test the code on my end and it works for me.
    I hope this helps 🙂

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Setting post_ID as content_ids’ is closed to new replies.