Results 1 to 2 of 2

Thread: Adding a filter to the content only on custom post types...

  1. #1
    whyisjake's Avatar
    whyisjake is offline Hello World
    Join Date
    Jun 2010
    Location
    Saratoga Springs, UT
    Posts
    1

    Default Adding a filter to the content only on custom post types...

    So, I wrote a plugin that adds a paypal button after the content of a custom post type. Is there a way to filter the_content so that the plugin is only added on custom post types?

    This is what I have now:


    PHP Code:
    function add_some_stuff($content) {
        global 
    $shortname;
        if (
    get_post_type() == 'the_store' ) {
            
    $display get_post_custom_values('thestore_display');
            if(
    $display[0]){
                
    $item_name the_title(''''false);
                
    $shopping_url get_permalink();
                
    $item_number get_the_ID();
                
    $amount get_post_custom_values('thestore_price');
                
    $amount $amount[0];
                
    $shipping get_post_custom_values('thestore_shipping');
                
    $shipping $shipping[0];
                
    $shipping2 get_post_custom_values('thestore_shipping2');
                
    $shipping2 $shipping2[0];
                
    $business get_option($shortname.'_paypal');
                
    $handling get_post_custom_values($shortname.'_handling');
                
    $handling $handling[0];
                
    $currency get_post_custom_values('thestore_currency');
                
    $currency $currency[0];
                
                
    $paypal = <<<PAYPAL
                        <form method="post" action="https://www.paypal.com/cgi-bin/webscr" target="paypal">
                        <input type="hidden" name="cmd" value="_cart">
                        <input type="hidden" name="business" value="$business">
                        <input type="hidden" name="item_name" value="$item_name">
                        <input type="hidden" name="shopping_url" value="$shopping_url">
                        <input type="hidden" name="item_number" value="$item_number">
                        <input type="hidden" name="amount" value="$amount">
                        <input type="hidden" name="currency_code" value="$currency">
                        <input type="hidden" name="shipping" value="$shipping">
                        <input type="hidden" name="shipping2" value="$shipping2">
                        <input type="hidden" name="handling_cart" value="$handling">
                        <input type="hidden" name="bn"  value="ButtonFactory.PayPal.001">
                        <input type="image" name="add" src="http://www.powersellersunite.com/buttonfactory/sc-but-01.gif">
                        </form>
    PAYPAL;
                
                
                
                return 
    $content.$paypal;
            }
        }
    }

    add_action('the_content''add_some_stuff'); 
    The problem is, when there is no paypal link, none of the content shows up... Driving me crazy.

    Thanks

  2. #2
    DD32 is offline Hello World
    Join Date
    Jul 2009
    Posts
    39

    Default

    > The problem is, when there is no paypal link, none of the content shows up... Driving me crazy.

    You're only returning the content within the paypal if.
    Add another "return $content;" before the closing brace and you'll be right.

    > if (get_post_type() == 'the_store' ) {
    is probably the best way to only apply to the_store post types (Assuming your use of get_post_type() is correct, I'm not sure of its args). Else just use global $post; and work off that

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •