Viewing 14 replies - 1 through 14 (of 14 total)
  • Plugin Author Evan Herman

    (@eherman24)

    Hey zaratemartinez,

    At the moment there is no way, but that is a great idea for the next release.

    Currently, the plugin queries all posts and pages and builds a drop down of the results. I would love to be able to build in a filter that allows users to specify a custom post type to include in that drop down as well.

    If you’d like, I can provide you with some code that will get it done for you, but it would involve editing some core code of the plugin. Hopefully in the next release I’ll squeeze that feature in, so when you update the changes won’t be lost.

    If you’d like I can provide some instruction on that, just let me know.

    And thank you for the kind words regarding the plugin!

    Evan

    Plugin Author Evan Herman

    (@eherman24)

    Hey again Zaratemartinez,

    I’m not sure if you’d be interested in using this, but I’m sure another user is going to come along and ask the same question, so here is a reasonable solution until version 5.1 is released. We only need to edit a single file, and two lines of code…so here it goes!

    Inside of the main class file, class.yksemeBase.php located in yikes-inc-easy-mailchimp-extender/classes/class.yksemeBase.php, you’ll find the query the pulls in all of our posts and creates the drop down.

    On line 2678, we set up the arguments for our post query :

    $args_posts = array( 'numberposts' => -1);

    You’ll want to replace that line with the following two lines of code :

    $post_types = apply_filters( 'yks_redirect_add_post_types' , array( 'post' ) , 10  );
    $args_posts = array( 'post_type' => $post_types , 'numberposts' => -1);

    And that’s all for editing the plugin. Now you can easily write a function that will hook into the query and add our new custom post type to the mix. I’m not entirely sure what your portfolio custom post type is registered as, maybe it’s portfolio so I’ll use that as the example.

    You’ll want to add the following into your active themes functions.php file :

    function add_portfolio_post_type_to_yikes_redirect_dropdown( $post_array ) {
    	$post_array[] = 'portfolio';
    	return $post_array;
    }
    add_filter( 'yks_redirect_add_post_types' , 'add_portfolio_post_type_to_yikes_redirect_dropdown' );

    Once that’s in your theme file, you’ll want to make sure ‘portfolio’, that I have in the function is the same post type name as your portfolio post type. Then save the file, and your portfolio items should appear in the drop down on the settings page.

    Thanks,
    Evan

    Thread Starter zaratemartinez

    (@zaratemartinez)

    Thank you very much. The code work flawlessly ??

    Plugin Author Evan Herman

    (@eherman24)

    No problem at all! I’m glad that worked for you. We’ll get that into the next release so you won’t loose the changes.

    Thanks for choosing our plugin ??

    Evan

    This is great. Is there any way to change the code to also hard wire in a url to forward to?
    Thank you.

    Plugin Author Evan Herman

    (@eherman24)

    Hi Rsenescu,

    Do you mean add an additional option to select where you can specify a custom URL, say https://www.wikipedia.org or something similar?

    Correct. That would be ideal.
    For now, I’d also be happy with any advice to edit the code you gave above to go to one specific url like https://www.wikipedia.org .
    Much thanks for your great support,
    Reid

    Plugin Author Evan Herman

    (@eherman24)

    No problem at all Reid,

    Give me a few minutes and I’ll write up a step by step to include a custom URL into that dropdown.

    Thanks!

    Evan

    Plugin Author Evan Herman

    (@eherman24)

    Hi again Reid,

    So as above, in the main class file ‘class.yksemeBase.php’ you’ll find the two sections where we spit out the list of posts and pages. On line 2702 begins the Posts, and line 2710 begins the Pages options.

    Directly below this line:

    <optgroup label="Pages">
      <?php
        foreach( $pages as $page ) : ?>
          <option <?php if(isset($field['page_id_'.$list['id']])) { selected( $field['page_id_'.$list['id']], $page->ID ); } ?> value="<?php echo $page->ID; ?>"><?php echo $page->post_title; ?></option>
        <?php endforeach; ?>
    </optgroup>

    You’ll want to add the following:

    <optgroup label="Custom URLs">
       <option <?php selected( $field['page_id_'.$list['id']] , 'https://www.wikipedia.org' ); ?> value="https://www.wikipedia.org">Wikipedia</option>
    </optgroup>

    As you can see the value parameter in the <option> tag is the url that the user will be redirected too. The text “Wikipedia” is what is displayed within the dropdown menu. Basically so you know what the option is. If you create new URL’s to add to the list, you’ll want to make sure that the value parameter on the option matches the URL in the selected function (which dictates which value was selected upon saving the form).

    Once you have the code in the file, save it and reload the ‘Manage List’ page. You should then see the “Wikipedia” option at the bottom of the dropdown.

    Let me know if that works for you. I’d like to get a custom filter built into the next version as well that will allow users to populate this dropdown with custom URLs and Custom Post Types.

    Thanks,
    Evan

    Hi Evan,
    The URL name, Wikipedia, appeared in the drop down. But, it doesn’t redirect. Am I supposed to delete anything or use any of the code from your original post to Zaratemartinez? I don’t know php, so it’s possible I’m missing something trivial. My apologies.
    Thank you for your help.

    Plugin Author Evan Herman

    (@eherman24)

    Hi Reid,

    No it should have worked out of the box. Let me take a second look as to why it may not be working. I’ll post back here shortly!

    Evan

    Plugin Author Evan Herman

    (@eherman24)

    Hi Reid,

    After some testing I realized that we are passing a full URL back into a get_permalink function, which fails when passing in something like wikipedia.org.

    You’ll need to set up a conditional to check weather a post ID is returned or if an actual URL is being returned.

    You’ll want to adjust this in two locations inside of class.yksemeBase.php.

    First is line 2957 and the next is on line 3078:

    You’ll want to look out for the following line:

    $redirect_url = get_permalink($redirect_page); // get the permalink of the page we are going to redirect too

    and replace it with :

    $redirect_url = get_permalink($redirect_page); // get the permalink of the page we are going to redirect too
       if ( is_numeric( $redirect_page ) ) {
     	$redirect_url = $redirect_url;
       } else {
    	$redirect_url = $redirect_page;
       }

    You’ll want to change it in both locations that I have mentioned above. One is for the <div> layout and the other is for the <table> layouts.

    I’ve just tested and was successfully redirected to the wikipedia page on form submission.

    Let us know if that works or if you need further help.

    Thanks!
    Evan

    That worked! Thanks for the great support.

    Plugin Author Evan Herman

    (@eherman24)

    No problem at all, glad we got that working and squared away ??

    Have a great evening, and thanks for the positive review !

    Evan

Viewing 14 replies - 1 through 14 (of 14 total)
  • The topic ‘URL Redirect to Portfolio’ is closed to new replies.