Forum Replies Created

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter MikeZH

    (@mikezh)

    That’s it! Thank you for your support! With your help, i was able to setup the filter.
    I’m now just returning a empty value, or the real URL for the detail-page, depending on the value of the status. Exactly what i was looking for.

    For anyone, searching for a similar solution, here is the final code.
    The status has a value from 0-99, and only members with a status <2 will have a detail-link. All others won’t have a link to the detail page.

    add_filter( 'pdb-single_record_url', 'toggle_detail_url', 10, 2 );
    
    function toggle_detail_url( $url, $record_id ) {
    	
    	$record = Participants_Db::get_participant($record_id);
    	$status = $record['status'];
    	
    	if ($status > 2) {
      		return '';
    		}
    	else
    		{
      		return $url;
    		}
    	
    }
    Thread Starter MikeZH

    (@mikezh)

    I was just testing, if my code would work at all… i’ve added now the else argument too, so just for testing, there should be one or the other URL placed as page link.
    but, i still get an error. As far as i understand, the line with the $status is the problem, but i don’t know, how i can ask for the value of the “status” field from the database… I copied this example from else where, but it seems not to work like i expected.

    This is the updated code:

    add_filter( 'pdb-single_record_url', 'toggle_detail_url' );
    
    function toggle_detail_url() {
    	
    	$status = $this->participant_values['status'];
    
    	if ($status > 2) {
      		return 'http://example.com';
    		}
    	else
    		{
      		return 'http://google.com';
    		}
    	
    }

    Error Message i get, when trying to show the list:

    Fatal error: Uncaught Error: Using $this when not in object context in /home/schwei10/public_html/wp-content/plugins/code-snippets/php/snippet-ops.php(361) : eval()'d code:5 Stack trace: #0 /home/schwei10/public_html/wp-includes/class-wp-hook.php(290): toggle_detail_url('https://schweiz...') #1 /home/schwei10/public_html/wp-includes/plugin.php(206): WP_Hook->apply_filters('https://schweiz...', Array) #2 /home/schwei10/public_html/wp-content/plugins/participants-database/classes/PDb_Base.php(1122): apply_filters('pdb-single_reco...', 'https://schweiz...', 1, NULL) #3 /home/schwei10/public_html/wp-content/plugins/participants-database/classes/PDb_Base.php(1138): PDb_Base::set_filter('pdb-single_reco...', 'https://schweiz...', 1, NULL) #4 /home/schwei10/public_html/wp-content/plugins/participants-database/participants-database.php(816): PDb_Base::apply_filters('single_record_u...', 'https://schweiz...', 1) #5 /home/schwei10/public_html/wp-content/plugins/participants-database/classes/PDb_Field_Item.php(620): Participants_Db: in /home/schwei10/public_html/wp-content/plugins/code-snippets/php/snippet-ops.php(361) : eval()'d code on line 5

    Thread Starter MikeZH

    (@mikezh)

    Hi!
    Thank you for the feedback.

    Since i’m quite new to the use of Filters in WordPress, i’m struggling a bit.

    I’m even not sure, where should i place the filter code? I’ve added it to the Code Snippet plugin, it also seems to work, without a specific filtering based on values.

    But as soon as i try to filter for a status value, i only get an error on the frontend.

    What am i doing wrong here?

    Currently testing with this code.
    The detail page URL should be used, as long as the Status value is < 3 (or removed, if status value is > 2, like in the request below).

    add_filter( 'pdb-single_record_url', 'toggle_detail_url' );
    
    function toggle_detail_url() {
    	
    	$status = $this->participant_values['status'];
    
    	if ($status > 2) {
      		return 'http://example.com';
    		}
    	
    }

    Hi!

    Check out this blog post, there you find the solution for this:
    http://www.graphene-theme.com/announcement/graphene-1-9-4-update/

    You need an additional plugin, since shortcodes aren’t allowed anymore in Themes.

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