mfalk75
Forum Replies Created
-
Forum: Developing with WordPress
In reply to: Get Random Author if had post in last monthCorrect, it’s the first one.
$role = 'author';
Thanks!Forum: Developing with WordPress
In reply to: Get Random Author if had post in last monthThankyou @bcworkz for all the information. I am defining the variable as author in the code when I call it from my single.php file. So I should be OK then correct? Otherwise, I might just remove the variable and define it as author in the function.
Forum: Developing with WordPress
In reply to: Get Random Author if had post in last monththe code part is backticks
Forum: Developing with WordPress
In reply to: Get Random Author if had post in last monthah, OK, I’m completely unfamiliar with using mySQL but I did what you said but still couldn’t get it to work properly. Instead I changed it to this and now it seems to be working fine.
function get_random_author_wpa91320($role){ global $wpdb; //this will get all users with posts $ids = $wpdb->get_col(" SELECT DISTINCT post_author FROM $wpdb->posts, $wpdb->usermeta WHERE post_type = 'post' AND post_date > NOW() - INTERVAL 1 MONTH AND post_status = 'publish' AND user_id = <code>post_author</code> AND meta_key = 'wp_capabilities' AND meta_value LIKE '%\"{$role}\"%' " ); return $ids[rand(0,count($ids) -1)]; }
So basically it’s my original function with the added post_date part. I could not get it to work using prepare instead of get_col for security as mentioned by @catacaustic. My main question is this function secure?
Forum: Developing with WordPress
In reply to: Get Random Author if had post in last monthThank you @bcworkz and @catacaustic. It was the post_author part, I added the backticks and my old code is now working again. I tried to do the same thing with the code utilizing 1 month limit provided by @catacaustic. Took out the < code > tags and replaced them with backticks. Didn’t work however. I ran the code in phpMyAdmin but honestly it’s all a little too advanced for me. haha Here was the results.
ERROR: Unknown Punctuation String @ 15 STR: -> SQL: $query = $wpdb->prepare(" SELECT DISTINCT post_author FROM $wpdb->posts, $wpdb->usermeta WHERE post_type = 'post' AND post_status = 'publish' AND post_date >= %s AND user_id = <code>post_author</code> AND meta_key = 'wp_capabilities' AND meta_value LIKE %s", date ('Y-m-d H:i:s', strtotime ('-1 month')), '%'.$role.'%' ) SQL query: Documentation $query = $wpdb->prepare(" SELECT DISTINCT post_author FROM $wpdb->posts, $wpdb->usermeta WHERE post_type = 'post' AND post_status = 'publish' AND post_date >= %s AND user_id = <code>post_author</code> AND meta_key = 'wp_capabilities' AND meta_value LIKE %s", date ('Y-m-d H:i:s', strtotime ('-1 month')), '%'.$role.'%' ) MySQL said: Documentation #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '$query = $wpdb->prepare(" SELECT DISTINCT post_author FROM $wpdb->post' at line 1
Forum: Developing with WordPress
In reply to: Get Random Author if had post in last monthah, thank you @bcworkz, I think I was staring at it for too long. I made that change and figured it was going to work again but still no luck. Is there anything wrong with this last part perhaps:
AND meta_value LIKE '%\"{$role}\"%'
Forum: Developing with WordPress
In reply to: Get Random Author if had post in last monthI think it’s something to do with the wordpress role messing things up but not sure
Forum: Developing with WordPress
In reply to: Get Random Author if had post in last monthOK, when I get home I will try that. In the mean time trying to get your new version of the code to work I broke the old code lol. My luck. This was the function.
function get_random_author_wpa91320($role){ global $wpdb; //this will get all users with posts $ids = $wpdb->get_col(" SELECT DISTINCT post_author FROM $wpdb->posts, $wpdb->usermeta WHERE post_type = 'post' AND post_status = 'publish' AND user_id = <code>post_author</code> AND meta_key = 'wp_capabilities' AND meta_value LIKE '%\"{$role}\"%' " ); return $ids[rand(0,count($ids) -1)]; }
And I was calling the function like this
<?php if ( is_single() ) : ?> <?php $user = get_user_by('id', get_random_author_wpa91320('author') ); $ad = xprofile_get_field_data( 'AD', $user->ID ); if (!empty($ad)) { ?> <div class="travel-blog-banner"> <span class="widget img"> <a href="<?php echo xprofile_get_field_data( 'AD', $user->ID ); ?>" target="_blank" rel="friend" rel="noopener"><?php echo xprofile_get_field_data( 'AD', $user->ID ); ?></a> </span> </div> <?php } else {} ?> <?php endif; // is_single() ?>
Do you see something I screwed up? Need some fresh eyes I think. I had it working now it suddenly stopped. What would be better though if I could get your version of the code to work. Thanks so much
- This reply was modified 7 years, 9 months ago by mfalk75.
Forum: Developing with WordPress
In reply to: Get Random Author if had post in last monthThanks so much for helping @catacaustic. Am I correct that in using your code I would have to change $query to $ids so the whole function would look like this.
function get_random_author_wpa91320($role){ global $wpdb; //this will get all users with posts $ids = $wpdb->prepare(" SELECT DISTINCT post_author FROM $wpdb->posts, $wpdb->usermeta WHERE post_type = 'post' AND post_status = 'publish' AND post_date >= %s AND user_id = <code>post_author</code> AND meta_key = 'wp_capabilities' AND meta_value LIKE %s", date ('Y-m-d H:i:s', strtotime ('-1 month')), '%'.$role.'%' ); return $ids[rand(0,count($ids) -1)]; }
Forum: Developing with WordPress
In reply to: Add to end of esc_urlOK, thank you so much for all the information. I will let you know how it goes once I figure out what method of attack I’m going to use.
Have a great day!
Forum: Developing with WordPress
In reply to: Add to end of esc_urlNo, you are reading my mind haha. My idea of working on the categories is to get rid of that right hand cat navigation so we are on the same page. It does do a little more then the left hand navigation as it goes down a third level to differentiate the continents by region. So Asia then is separated into Cambodia, China, etc.
I sort of want to keep the navigation out of the right sidebar as if you are on mobile it shows up on the bottom of the page almost.
I think my idea is to take the post of the main category pages like Places to Go and instead make a image grid navigation. Then when you pick Asia there will still be a image grid. Not until you pick like Cambodia, China, etc will you go to the category page. From there I want the user to be able to sort the results by the activity filters. Are the filters you speak of any better for SEO than the ones wordpress already has in place by using a URL like: mysite.com/category/places-to-go/asia/china+hiking
I realize I’m not getting anything SEO from that it at that point as the Page Title is still China in my browser but at that point in the navigation I’m just trying to help the user sort all the post in China by activity if they wish. It’s really about the user at that point.
Saying I did want to just create a number of links at the top of the category page that appends the activity term to the current category url. How do I do that just in case I decide to go that route. I have this already working to return the current category page.
<?php $categories = get_the_category(); if ( ! empty( $categories ) ) { echo '<a href="' . esc_url( get_category_link( $categories[0]->term_id ) ) . '">' . name-of-activity . '</a>'; } ?>
In the above href statement where and how to I add the term +name-of-activty so the URL
mysite.com/category/places-to-go/asia/china/
becomes this URL
mysite.com/category/places-to-go/asia/china+name-of-activityThanks again!
Forum: Developing with WordPress
In reply to: Add to end of esc_urlOK, you gave me a lot to think about. LOL, thanks for that. My two main categories are Places to Go (All the Destinations) and Things to do (All the Activities) Well, you can get a quick look at my category structure here if you care to. https://www.roundworldtravels.com My basic thought is it’s too much. For instance, just viewing hiking and seeing posts from all over the world or just viewing china and seeing posts about anything and everything don’t really help anyone.
From what you said I think this “activities on a location page to be more like a filter of current results instead of links to specific activities for the location? A series of checkboxes perhaps, the more that are selected, the greater the results?” may be a better solution.
Like if someone arrived on the China Category by default all posts would show up but there would be some empty check-boxes that you could select and then hit a button that said “filter results” or something.
Thanks again for helping me!
Forum: Developing with WordPress
In reply to: Add to end of esc_urlHi @bcworkz, thanks for responding. I probably didn’t explain myself very well. The link mysite.com/category/places-to-go/asia/china+hiking already works. I can type it in my browser and I get posts only if they are assigned to both categories, china and hiking. I didn’t realize I could even do that until I saw this post: https://www.ads-software.com/ideas/topic/combine-multiple-categories-in-one-menu-item
So, what I’m trying to do is include a few different links in my category template. I figured if I can make a link that returns the current category page and then appends something like “+hiking” on the end it would make it so I didn’t have to create separate category templates for each category. I just want to append my activity categories to my destination categories.
But now as I say this I think I just realized that when they click through to that link the other links would no longer be valid as they would return something like mysite.com/category/places-to-go/asia/china+hiking+sightseeing
I don’t know, maybe I’m going about this the wrong way and using the query args would be a better solution. I’m really trying to make my navigation on my site a little more friendly. Could you point my toward some examples, I’m not sure I know how to fully implement that.
Thanks!
Forum: Fixing WordPress
In reply to: WordPress Gallery only linking to attachmentYup, I’m experiencing this as well. Anyone know a fix? I know i can simply go switch to attachment and then back to file but I need it to default that way. I work with multiple people on a blog and I can’t seem to make them all do this. They forget, etc. thanks
Forum: Plugins
In reply to: [nrelate Related Content] [Plugin: nrelate Related Content] Partner SettingsThanks Katrina, my site URL is https://www.gearupandplay.com
The Partner site URL I’m trying to link with is https://www.thenomadicfamily.com/It’s been over 2 days.
Also, my other question. Lets say I am showing 4 related post and I set the option to 1 for Maximum number of related posts to display from this site’s blogroll. Will it always show 1 from the partner even if my site has content that is more closely related?
Thanks again