Need help allowing user to "rewrite" the slug of a custom post with Option Tree without getting an error

196 posts
  • Elite Author
  • Sold between 250 000 and 1 000 000 dollars
  • Bought between 500 and 999 items
  • Canada
  • Exclusive Author
  • Has been a member for 2-3 years
  • Referred between 50 and 99 users
DanyDuchaine says

Hey guys,

So here is my problem, I have a custom post and I want to allow the user to specify the slug of the custom post as well as the taxonomy from the Option Tree dashboard so here is what I did : http://snippi.com/s/l59xl31

Unfortunately, it give me this error :

WARNING: wp-includes/functions.php:928 – Cannot modify header information – headers already sent by (output started at /Users/kailoon/Sites/wp35/wp-content/themes/MissionWP/includes/cpt-causes.php:4)

I’m pretty sure it’s simple but I can’t find how to fix this.

Can someone help?

Thanks!

331 posts
  • Exclusive Author
  • Sold between 5 000 and 10 000 dollars
  • Has been a member for 4-5 years
  • Europe
  • Microlancer Beta Tester
  • Bought between 1 and 9 items
  • Referred between 1 and 9 users
dekciw says

1. uft-8 without BOM

2. no blank lines before <?php

3. remove all unnecessary white space below the code

4. do not use ?> at the end of code

EDIT: Just checked my CPT snippet, it looks EXACTLY the same. :D Even this line:
            'description' => 'Easily lets you create some beautiful portfolios.',
:D
196 posts
  • Elite Author
  • Sold between 250 000 and 1 000 000 dollars
  • Bought between 500 and 999 items
  • Canada
  • Exclusive Author
  • Has been a member for 2-3 years
  • Referred between 50 and 99 users
DanyDuchaine says

1. uft-8 without BOM

2. no blank lines before <?php

3. remove all unnecessary white space below the code

4. do not use ?> at the end of code

EDIT: Just checked my CPT snippet, it looks EXACTLY the same. :D Even this line:
            'description' => 'Easily lets you create some beautiful portfolios.',
:D

OMG where have you find it? Mine come from my friend : OTOTW

:)

331 posts
  • Exclusive Author
  • Sold between 5 000 and 10 000 dollars
  • Has been a member for 4-5 years
  • Europe
  • Microlancer Beta Tester
  • Bought between 1 and 9 items
  • Referred between 1 and 9 users
dekciw says

Actually, don’t think that I’m accusing you of code stealing or something like that – I do not actually care if someone uses my snippets, etc. I’ve just said it as a fun fact :D You can check my cpt-portfolio.php here -> http://snippi.com/s/g9fwjch – and it works OK. So you’d better check for the stuff I’ve mentioned in my previous post.

Btw, I remember typing those descriptions myself. And never bought any OTOTW items :D

63 posts
  • Exclusive Author
  • Has been a member for 1-2 years
  • Microlancer Beta Tester
  • Bought between 10 and 49 items
  • Sold between 10 000 and 50 000 dollars
PrimeThemes says

I suggest use apply_filters for dynamic variable like this,

line 29
'rewrite' => array( 'slug' => apply_filters('custom_causes_post', 'causes') ),
line 58
'rewrite' => array( 'slug' =>apply_filters('custom_causes_tax', 'item-type') )
and in your functions.php,
add_filter('custom_causes_post', 'danny_causes_custom_slug');
function danny_causes_custom_slug(){
     global $options;

     $url_rewrite = $options['theme_causes_item_url'];
     $slug = ( !$url_rewrite ) ? 'causes' : $url_rewrite;

     return $slug;
}

add_filter('custom_causes_tax', 'danny_causes_custom_tax_slug');
function danny_causes_custom_tax_slug(){
     global $options;

     $url_rewrite = $options['theme_causes_item_type_url'];
     $slug = ( !$url_rewrite ) ? 'causes' : $url_rewrite;

     return $slug;
}
196 posts
  • Elite Author
  • Sold between 250 000 and 1 000 000 dollars
  • Bought between 500 and 999 items
  • Canada
  • Exclusive Author
  • Has been a member for 2-3 years
  • Referred between 50 and 99 users
DanyDuchaine says

Actually, don’t think that I’m accusing you of code stealing or something like that – I do not actually care if someone uses my snippets, etc. I’ve just said it as a fun fact :D You can check my cpt-portfolio.php here -> http://snippi.com/s/g9fwjch – and it works OK. So you’d better check for the stuff I’ve mentioned in my previous post. Btw, I remember typing those descriptions myself. And never bought any OTOTW items :D

Doesn’t it come from Option Tree v2? :)

@PrimeThemes : Thanks! Will try this :)

741 posts
  • Has been a member for 5-6 years
  • Sold between 50 000 and 100 000 dollars
  • Exclusive Author
  • Most Wanted Bounty Winner
  • Bought between 50 and 99 items
  • Poland
  • Referred between 10 and 49 users
Orbital_Themes says

One small suggestion is that you probably shouldn’t flush_rewrite_rules on every page load. This should be done only once when an option for rewrite slug is changed.

2001 posts
  • Elite Author
  • Author had a Free File of the Month
  • Has been a member for 4-5 years
  • Austria
  • Exclusive Author
  • Interviewed on the Envato Notes blog
  • Microlancer Beta Tester
+3 more
revaxarts says

One small suggestion is that you probably shouldn’t flush_rewrite_rules on every page load. This should be done only once when an option for rewrite slug is changed.

+1 please never call it on every page load :crying:

196 posts
  • Elite Author
  • Sold between 250 000 and 1 000 000 dollars
  • Bought between 500 and 999 items
  • Canada
  • Exclusive Author
  • Has been a member for 2-3 years
  • Referred between 50 and 99 users
DanyDuchaine says

Ok I won’t I won’t :)

by
by
by
by
by
by