• Resolved mrine7

    (@mrine7)


    Hi there,

    I would like to retrieve the ‘members only’ checkbox value in a custom php template.

    I need some help with this, I’ve tried a lot of things.

    So what i want to accomplish is:

    if $membersonly == true {
    // do something
    }

    Hope to hear from you!

    (also, I’ve tried to accomplish the above with Advanced Custom Fields, but AFC doesn’t seem to be working with Download Monitor? Is this correct? Cause I’ve used AFC all over my website for other purposes, but with download monitor i can’t seem to call the values from the database.)

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Contributor Barry Kooij

    (@barrykooij)

    Hey there,

    To do this it is important you have the ID of the download in your custom template. Let’s say you’ve put the download ID in the variable $download_id.

    With the above information in mind, the following code should work:

    
    try {
    	/** @var DLM_Download $download */
    	$download = download_monitor()->service( 'download_repository' )->retrieve_single( $download_id );
    
    	if ( true === $download->is_members_only() ) {
    		// download is members only
    	}
    
    } catch ( Exception $exception ) {
    	// download with given ID not found
    }
    

    Kind Regards,

    Barry Kooij

    Thread Starter mrine7

    (@mrine7)

    Dear Barry,

    This doesn’t seem to work 🙁

    Is the download_id automatically created and stored by the download monitor plugin?

    I hope you can help me.

    Thread Starter mrine7

    (@mrine7)

    Hi Barry,

    I’ve managed to get this to work. But I’m wondering if this is a good (and healthy) solution. The fact that it works, doesn’t mean it’s good.

    <?
    $freedownload = $dlm_download->is_members_only();
     if ( $freedownload == 1 ) {
      echo "free";
    }
     else {
      echo "not free";
    }
    ?>

    Thanks!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Retrieving the ‘members_only’ value from databbase’ is closed to new replies.