Sticky on top plugin

Hi,
I get website with Classipress theme and I use sticky on top plugin to show featured ads on top.
The plugin display all featured ads, but I would like to plugin show only 3 featured ads randomly.
Here is the code

<?php add_filter('posts_clauses_request', 'tb_sticky_on_top' ); function tb_sticky_on_top( $sql ){ if( is_tax(APP_TAX_CAT) || is_search() ){ global $wpdb; $sticky_posts = get_option('sticky_posts'); if(!$sticky_posts) return $sql; $sql['fields'] = $sql['fields'].", IF( $wpdb->posts.ID IN ( ".implode(',',$sticky_posts)."), 3, 0) AS featured"; $sql['orderby'] = "featured DESC,". $sql['orderby']; } return $sql; } ?>

My testing website is: http://www.demo.com.hr/ad-category/sample/

Regards and thanks for help

Add a random and a limit to the query.

Thanks for your answer

Can you place it for me because I don´t know where to put it?
I can test it later and let know is it work.
The problem is that I bought plugin and now when I need some help, without answer from they support

regards

I need you help because I´m not a programmer

… and I would like to donate for that job too :slight_smile:

PM or Email me…

something like this maybe?

[php]SELECT ad_id
FROM ads.db
WHERE posts.ID = $sql[‘fields’]
ORDER BY RAND()
LIMIT 0,20[/php]

You NEVER EVER put variables in a query. You need to use prepared statements.

Thanks for trying to help Kevin, but I´m not a programmer.
Can you put that code in existing one?

Regards

It was the concept not the code that i was pointing out … i would never use a var in a query like that …

It was the concept not the code that i was pointing out ... i would never use a var in a query like that ..

You may know that, but noobs coming here for answers don’t know that. Even short pseudo answers should still be technically correct. Many people will just cut and paste and use the code because “it works”.

Haven’t seen you around here before. Welcome to the forum. :smiley:

I don´t know nothing about it.
It is a Plugin for classipress WP theme what I bought and I would like to someone help me with modification. For now, that plugin show all featured ads on top and I need to display only 3 or 5 featured ads per view randomly.

Any idea?

Sorry [member=86323]trevor1[/member] ,
I don’t go anywhere near Wordpress. I am sure someone else may help you.

[member=86323]trevor1[/member]

[member=46186]Kevin Rubio[/member] was meaning something like this. I too try and stay as far away from wordpress as possible…

this code is just an example to show you how a prepared statement would look with the information you provided.
[php]<?php

if ($stmt = $mysqli->prepare(“SELECT ad_id FROM ad_table ORDER BY RAND() LIMIT 10”)) {

?>[/php]
EDIT, realized i pasted the wrong code … here is the corrected.

here is a more complete code from a snippit of code i use for a bug report listing …
[php]$rand = “SELECT ROUND(RAND() * (SELECT COUNT(*) FROM Bugs))”;
$offset = $pdo->query($rand)->fetch(PDO::FETCH_ASSOC);
$sql = “SELECT * FROM Bugs LIMIT 1 OFFSET :offset”;
$stmt = $pdo->prepare($sql);
$stmt->execute( $offset );
$rand_bug = $stmt->fetch();[/php]

I appreciate your decision with wordpress and thanks for the effort

regards

Sponsor our Newsletter | Privacy Policy | Terms of Service