Extended explanation: I'm using post meta inside a loop on the category page to display thumbnails and I'd like to filter it so I can replace certain width values. E.g. if width="50" change it to width="75".
(I'm using a basic function with str_replace to add/replace by applying it to the the_content which works perfectly.)
How can I easily target the get_post_meta in the category page using a function?
(I'm online now and can test this quickly this. If all goes well I also have another question.)
Luis Abarca answers:
Had you try to use CSS ??
.thumnail {
width: 50px;
height: 75px;
}
Ina comments:
Hi Luis,
Thanks but I think it's a little more complex than just overriding it with CSS.
Ina comments:
I apologise and I stand corrected.
I didn't think I could target it and I'd had trouble before.
Francisco Javier Carazo Gil answers:
Hello Ina,
I don't understand you. You are saving a post_meta into a category page and you want to change this meta?
If it is correct, use the next one:
update_post_meta($post_id, $meta_key, $meta_value, $prev_value);
To get the ID of page:
$id = $wp_query->post->ID;
Ina comments:
Sorry if the question sounded rather vague but basically I have a custom field has images or video code dropped into it. Rather worry about editing individual dimensions, I'd just like to say target a width or a height using a function.
I can do it using a str_replace because obviousy I can target the_content, but these fields are being used on the Category page.
I hope that makes more sense.
Francisco Javier Carazo Gil comments:
Hi Ina,
You can directly use CSS as Luis says.
Another option, if you want to set the width into post_meta directly is SELECT all registers and UPDATE the registers you want.
$my_meta = 'metea';
$allmiles = $wpdb->get_results(
"
SELECT *
FROM $wpdb->postmeta
WHERE meta_key = %s
",
$meta_key
) ;
foreach($registers as $register)
{
if(your_condition($register))
update_post_meta();
}
Where your condition is a function where you:
* See if the information is a image
* Make any other checks
Ina comments:
Thank you for the fast response.
If you're suggesting as Luis that I can just use CSS, how do I override the width of an embedded video?
Francisco Javier Carazo Gil comments:
Ina,
If you are using videos with <object> tag, you can also use CSS.
object.style.width="50px"
But you can also do the other method and this way change the value saved. The condition would be something like:
if(ereg("vimeo",$meta_content))
And the UPDATE with the new value in the string. Remember to set height proportionally.
Julio Potier answers:
Hello
You can use an OutputBuffer code kind, i'll explain.
Ina comments:
Please do.
Arnav Joy answers:
what are you getting from get_post_meta
can you write syntax here for get_post_meta()
or please explain your question further.
Ina comments:
Hi Robin,
Please see my answer above. I hope that makes more sense.
Arnav Joy comments:
so you giving path of video or image in custom field.
Ina comments:
Yes, that's right.
The field will either have
<img src...
<object...
etc.
I just wasn't sure of my approach, since I didn't really think of it in terms of updating the field. I was thinking more along the lines of replacing certain strings using a function.
Perhaps the confusion is from the fact that you can easily target the_content or the_excerpt but this is on the category page.
Sébastien | French WordpressDesigner answers:
why do you not use the function [[LINK href="http://codex.wordpress.org/Function_Reference/the_post_thumbnail"]]the_post_thumbnail[[/LINK]] ??!
For example you can use
the_post_thumbnail( array(100,100) );
to have a thumb 100px X 100px
it's easy !