• Resolved cloutsca

    (@cloutsca)


    Hi Dennis,

    I noticed that the base slug for post categories was actually pulling the base slug for post_tags.

    Made a small correction to one of the plugin file and now it seems to work as expected.

    File: includes/MslsOptionsTax.php, Line: 45.
    I added the line 44 pulled $id in the is_category call and is_tag call.

    
    	/**
    	 * Factory method
    	 *
    	 * @codeCoverageIgnore
    	 *
    	 * @param int $id
    	 *
    	 * @return MslsOptionsTax
    	 */
    	public static function create( $id = 0 ) {
    		if ( is_admin() || ! empty( $id ) ) {
    			$obj = MslsContentTypes::create();
    
    			$id  = (int) $id;
    			$req = $obj->acl_request();
    		} else {
    			$id  = get_queried_object_id();
    			$req = is_category($id) ? 'category' : is_tag($id) ? 'post_tag' : '';
    		}
    
Viewing 10 replies - 1 through 10 (of 10 total)
  • Struggeling with the same issue, but it’s still not working with the code snippet from above on my site. It’s still using /tag/ for category links instead of the correct category base slug, maybe it needs to get replaced anywhere else also?

    Plugin Author Dennis Ploetner

    (@realloc)

    Hello @cloutsca,

    that’s interesting and it means that – because it works in your case – that there can be a situation when is_category or is_tag needs explicitly the ID of the queried object.

    @mattce is_category( $id ) should work for a category. It would mean that the WordPress API is not working here, what seems less probable. Please, describe your setup.

    Cheers,
    Dennis

    @dennis I’ve uploaded my steps on imgur: https://imgur.com/a/NGvu1l8

    I’m working with a standard archive.php without any further special rules or something, so there should not occur any conflicts with the theme itself.

    Thread Starter cloutsca

    (@cloutsca)

    One other thing I noticed…

    I first was using category and tag slugs composed of multiple tokens.

    On french site/blog:
    Post slug was: /publications/%postname%/
    Category slug was: publications/categories
    Tag slug was: publications/etiquettes

    On english site/blog:
    Post slug was: /posts/%postname%/
    Category slug was: posts/categories
    Tag slug was: posts/tags

    Even with the change I made (detailed in a comment above), problem was still occuring. So I revert back to use a single token slug for category and tag.

    On french site/blog:
    Post slug was: /publications/%postname%/
    Category slug was: categories-de-publication
    Tag slug was: etiquettes-de-publication

    On english site/blog:
    Post slug was: /posts/%postname%/
    Category slug was: post-categories
    Tag slug was: post-tags

    Problem was then solved with the solution I proposed (detailed in a comment above). But something else should probably need a fix here.

    Or maybe the conflict only occured because I was using the same slug start as for posts? I don’t know

    • This reply was modified 7 years, 4 months ago by cloutsca.
    Thread Starter cloutsca

    (@cloutsca)

    Wow ok… I don’t know what is going on now…
    I am pretty sure that my proposed fix was working late last night! :O
    Tested it again this morning and it seems that the problem occurs again.

    I am using twentyseventeen theme.

    Plugin Author Dennis Ploetner

    (@realloc)

    Hmmm … strange @cloutsca. Did you always a refresh of the permalinks (visiting the section in the admin)?

    @mattce The interesting var is $req because the plugin decides with its value what class to call.

    @all You don’t have any custom code in place?

    @dennis var_dump($req) outputs: “post_tag”, so the problems seems to be in the line

    $req = is_category($id) ? 'category' : is_tag($id) ? 'post_tag' : '';

    If I set $req manually to “category”, all links are working properly.

    var_dump(is_category()) delivers bool(true) also ( whereas var_dump(is_tag()) delivers bool(false) ).

    So it’s mistakenly setting post_tag in the line from above.

    • This reply was modified 7 years, 4 months ago by mattce.
    Thread Starter cloutsca

    (@cloutsca)

    Ok now I got it… I think.

    It has nothing to do with putting the $id or not in the is_category or is_tag function.

    Just enclose the 2 ternary statements like this:

    
    $req = (is_category() ? 'category' : (is_tag() ? 'post_tag' : ''));
    

    I probably did this the first time to fix it but conclude to the wrong fix.

    Plugin Author Dennis Ploetner

    (@realloc)

    Ok, thanks! Nice catch, version 2.1.1 is on the way…

    Thank you both, works like a charm 🙂

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

The topic ‘Base slug for post categories not pulled correctly’ is closed to new replies.