WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Capturing custom plugin slug from URL (6 posts)

  1. hodgeman
    Member
    Posted 5 years ago #

    Hi WordPress community,

    Long time user, first time plugin writer.

    I'm developing a custom exhibition/events plugin for our local Rotorua Museum website that I am converting to WordPress.
    I've got a custom database table that is storing all the information, and I've included a custom tag/slug/friendly url field for each entry.

    I'm now at the point of showing the information on separate pages with shortcodes to display the different exhibitions (current vs upcoming vs events). But now I'm stumped as to how I capture the unique slug from the URL for the exhibition/event and show the correct entry from the database for it on one page?

    Do I:

    a) Capture the URL/slug on the 404 error (index.php) page and redirect? - started...
    b) Write a custom mod_rewrite in my .htaccess file that points to the one 'exhibition detail' page?
    c) Try to use a shortcode some how?
    d) Create a generic non WordPress 'dynamic' old school php page?
    e) Give up and throw my toys out?
    f) None of the above?

    Here is the current site in development.
    http://72.29.81.173/~museum/index.php/exhibitions-events/now-showing/

    Any help, links, guidance, support would be gratefully appreciated.

    Cheers
    Adrian Hodge

  2. hodgeman
    Member
    Posted 5 years ago #

    I've just tried option c) which will work, but not the prettiest url.

    http://72.29.81.173/~museum/index.php/exhibitions-events/exhibition-details/?slug=dr-judith-dell-panny-john-bevan-ford

    Plus I have to use the plugin EXEC_PHP to pass the slug variable using $_GET to the shortcode variable.

    Is there a way to do this using my custom slug for each exhibition in the URL link?

    Back in 20hrs...

  3. hodgeman
    Member
    Posted 5 years ago #

    Option B)

    I've just tried adding a custom mod_rewrite rule but now I'm getting an apache error saying the server can't find the page requested, but it should be linking to the exact same page as the one in my last post:

    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    
    RewriteRule ^index.php/exhibitions-events/exhibition-details/([a-z\-]+)$	index.php/exhibitions-events/exhibition-details/?slug=$1 [L]
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    # END WordPress

    Is that one extra rule playing havoc with the default WordPress system?

    If I put in the first slash:

    RewriteRule ^/index.php/exhibitions-events/exhibition-details/([a-z\-]+)$	/index.php/exhibitions-events/exhibition-details/?slug=$1 [L]

    I end up on the 404 page

  4. hodgeman
    Member
    Posted 5 years ago #

    Ok, making some small progress...

    Have read http://codex.wordpress.org/Custom_Queries

    I just trying to code a rewrite rule using add_action('generate_rewrite_rules'... to convert

    /exhibition-details/{{EXHIBITION-SLUG}}

    to

    ?p=524&exhibition={{EXHIBITION-SLUG}}
  5. hodgeman
    Member
    Posted 5 years ago #

    Wow, this one on one support forum is so helpful...

    Do I need to explain things further for someone to understand my problem?
    I'd really would appreciate (LOVE) any assistance with this.

    My current rewrite function doesn't seem to help much

    function wp_exhibitions_rewrite_rules($wp_rewrite){
      $new_rules = array(
    		'index.php/(exhibitions-events/exhibition-details)/([a-z\-]+)' => 'index.php?pagename='.$wp_rewrite->preg_index(1).'&exhibition='.$wp_rewrite->preg_index(2)
    	);
      $wp_rewrite->rules = $new_rules + $wp_rewrite->rules;
    }

    I'm trying to get:

    http://72.29.81.173/~museum/index.php/exhibitions-events/exhibition-details/exiles-rudolf-boelee

    rewriting to:

    http://72.29.81.173/~museum/index.php/exhibitions-events/exhibition-details/?exhibition=exiles-rudolf-boelee
  6. hodgeman
    Member
    Posted 5 years ago #

    Finally stumbled over this thread:

    http://wordpress.org/support/topic/208830

    Which had a solution in it that I could use.

    Hip hip, hooray!

Topic Closed

This topic has been closed to new replies.

About this Topic