Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Rewrite code efficiently and add a function. WordPress

  • SOLVED

I am creating this football website that needs to be done in a short amount of time for the project size. I am dealing with three custom post types and a custom taxonomy. I poked around on the web and pieced together code that makes it work. Although, I am missing some functionality in the code. Let me explain.

The functionality I am missing is in the "Players" post type.
Players, has a meta box that the everything including the title field is hidden. (not included in array). This is because I want each player's first and last name separate. In fact, it only supports the custom meta box that I created for it. These are the fields: first name, last name, height, weight, number, position, and grade. I need the permalink and title (which is hidden) to reflect three custom field values. So it would look like this:

Title: $title = $number . " " . $first_name . " " . $last_name //03 John Smith
Slug: $slug = $number . "-" . $first_name . "-" . $last_name // http://mydomain.com/varsity/roster/03-John-Smith/

Lastly, I would like to have more control over my meta boxes. Right now they are in arrays and they are hard to format how I would like them. For example, for the players meta box I want the number, first_name, and last_name fields on the same line.

If anyone could help me out that would be wonderful!

Thanks!

Answers (3)

2010-07-18

Oleg Butuzov answers:

20 $ is a bit less for solution on this question. i se at least 3 hours of work here.


Austin Condiff comments:

How much would you do this for? (Be fair please...)


Oleg Butuzov comments:

but if you want to do it yourself... here is a plan.

use
add_rewrite_tag to add your custom values
Live example (WP Multilingual )



add_filter('query_vars', array('WPML', 'query_language'));
....
....
function query_language($variables){
global $wp_rewrite, $wpdb;
$variables[] = 'wpmllanguage';
$wp_rewrite->add_rewrite_tag('%wpmllanguage%', wpml::get_option(MULTILINGUAL_DOMAIN.'_concated'), 'wpmllanguage=');
return $variables;
}


Oleg Butuzov comments:

my hour rate is 25 - you can check any of links in my profile for a feedbacks or details.

ok. i am continue givine a peaces of code that can help anyone who will come with a same stuff here on this website.


Austin Condiff comments:

You've got a deal. I will raise the prize price to $75. Should I post the code here? This is my first post. =)


Oleg Butuzov comments:

i think will be better if you can pass me a access to the website so i can copy db and work in standalone mode or just simple pass me the db with your custom values. so i can continue.



Austin Condiff comments:

My database is pretty much empty except for test values. And I am testing it locally. Do you have a fresh wordpress install handy? or you can add the functions.php file to a new theme.


Oleg Butuzov comments:

all i need is just db + code you creating custom post type (slug of post type itself important)
i has wp installs. so you can provide a code for custom post type + db.

the result can be provided as code for functions.php or plugin.


Austin Condiff comments:

did you get that email and is that all you needed? a fuctions.php file would be great as a result.


Oleg Butuzov comments:

2Gustavo

solution for this is hooks, filter, rewrite tags ... etc.

2Austin

got the code.


Austin Condiff comments:

do you need anything else from me? It's 2am here and I need to get up at a decent time tomorrow. Just send me the finished code when your done.
austin[dot]condiff[at]gmail[dot]com

Thanks!


Oleg Butuzov comments:

ok.


Oleg Butuzov comments:

<strong>Guys... stop commenting...
</strong>
Issue resolved. Austin just sleeping now. its night in USA.

2010-07-18

Gustavo Bordoni answers:

[email protected]

I might have another solution.

But as Oleg Butuzov said its on Filters.


Austin Condiff comments:

What is your solution and what do you mean by filters?


Gustavo Bordoni comments:

I'm thinking on something that goes before the set up of the permalink, using filters to create this set up.

Using the hook add_filter('the_permalink ', 'my_function');.

My question is, do you have a specific category where this should happen or just when it's this custom_post_type??


Austin Condiff comments:

all categories in the taxonomy "teams"


Austin Condiff comments:

actually, just in the players post type. your referring to the slug rewrite, correct?


Gustavo Bordoni comments:

Ok, I was looking for this info to make something on the code to specify witch Posts I have to change the slug.


Austin Condiff comments:

i tried to do this on my own, but I couldn't find anything online (after my two day search). I am college aged, What is the best way to learn this (if you don't mind me asking), because schools don't really teach wordpress.


Gustavo Bordoni comments:

This level of wordpress You won't find any where... not on books... not even on the Codex this kind of info is well explained...

Yes... this is a problem on WordPress Codex... the lack of information on Hooks and Filters...

But keep an eye on the Trac is a good way, and another way to get on some real good info is to look up for on the files, that are very well commented.

Almost all files on WordPress have a good info for a developer.


Austin Condiff comments:

Their codex is very lacking. I tried asking several questions on their forums and for all three posts, I didn't get a single response. Here it was almost instantanious. Well money does help, but these forums are a really good idea. Thanks for the tip though. I will follow the trac and take a look at the wordpress files.


Gustavo Bordoni comments:

To starters the info is kind of very good but when you start to dig this system...

2010-07-18

Jared Williams answers:

I know about custom post types and taxonomies very well. Contact me directly for help with this.
[email protected]


Jared Williams comments:

There isn't documentation on this type of thing anywhere, that's why I've studied the WP source to learn it.


Jared Williams comments:

Perhaps some of this code can help you in some way at all.

It's hard to help not know what you're code looks like or how it's set up. This is a couple ways to create some meta boxes.


// Tell WP that you want these custom areas creating
function admin_init(){
add_meta_box("price-meta", "Price", "product_price", "product", "side", "low"); // the price field
add_meta_box("price_additions", "Price additions", "price_additions", "product", "side", "low"); // the additions to the price
add_meta_box("additional_info", "Additional Information", "additional_info", "product", "advanced", "low"); // the additions to the price
}


// How to create one sigle input area
function product_price(){
global $post;
$custom = get_post_custom($post->ID);
$product_price = $custom["product_price"][0];
// break out & write the html for this
?>
<label>Price (£): </label>
<input name="product_price" value="<?php echo $product_price; ?>" />
<?php
}


// How to create multiple inputs in a grouped area
function price_additions() {
global $post;
$custom = get_post_custom($post->ID);
$tax = $custom["tax"][0];
$pandp = $custom["pandp"][0];
$barcode = $custom["barcode"][0];
// break out & write the html for this
?>
<label>Tax (%): </label>
<input name="tax" value="<?php echo $tax; ?>" /><br />
<label>P&P (£): </label>
<input name="pandp" value="<?php echo $pandp; ?>" /><br />
<label>Barcode: </label>
<input name="barcode" value="<?php echo $barcode; ?>" />
<?php
}


Jared Williams comments:

I would assume that you are using this code in your register_post_type() array, but incase not, there is a bug with permalinks in post types.

This is one way to fix it:
rewrite' => array('slug' => 'posttypeslug'),

many people just use rewrite' => true, which causes permalinks to not work.


Jared Williams comments:

You might want to also try the get_post_permalink() function too. This is new in 3.0.