PHP - Pull Post From A Specific Wordpress Category
Hi, im looking to pull 3 posts from a specific Wordpress Category. At the minute I can pull 3 latest posts and display them in a flash banner using the code below.
Code: [Select] SELECT yah_posts.*, yah_postmeta.* FROM yah_posts LEFT JOIN yah_postmeta ON yah_posts.ID = yah_postmeta.post_id WHERE yah_postmeta.meta_key = 'largeimage' && yah_posts.post_status = 'publish' ORDER BY post_date DESC LIMIT 3 I want to be able to pull 3 latest posts from a specific category instead of just 3 latest posts from every category. I have put together this code below, but it doesn't seem to be working Code: [Select] $query = "SELECT yah_posts.*, yah_postmeta.* FROM yah_posts LEFT JOIN yah_postmeta ON yah_posts.ID = yah_postmeta.post_id AND LEFT JOIN $yah_term_taxonomy ON($yah_term_relationships.term_taxonomy_id = $yah_term_taxonomy.term_taxonomy_id) WHERE yah_postmeta.meta_key = 'largeimage' && yah_posts.post_status = 'publish' AND $yah_term_taxonomy.term_id = '1' AND $yah_term_taxonomy.taxonomy = 'category' ORDER BY post_date DESC LIMIT 3"; Similar TutorialsHope someone here can help me. Ive been commissioned to convert a template to wordpress that includes a portfolio... I built a portfolio page from a custom post type. that works. Items are categorized with a custom taxonomy named port_cats. that works also On the portfolio page, there is tabbed content built with jquery to show and hide items by category. So theres a category nav menu, plus each item wrapped in classes to show and hide. Im stuck on plugging this in correctly, and am SO CLOSE. I have the category nav list working, but having trouble getting worpress to read the correct category slug inside the loop. Heres how the jquery needs to work: for the menu: Code: [Select] <li><a href="#" rel="category-slug">Category Name</a></li> to hide and show the items: Code: [Select] <ul> <li class="category-slug"> title/thumb/content </li> </ul> Heres my code: Code: [Select] <ul class="select"> <?php //list custom portfolio categories $taxonomy = 'port_cats'; // define portfolio categories from taxonomies in functions.php $tax_terms = get_terms($taxonomy); foreach ($tax_terms as $tax_term) { echo '<li><a href="#" rel="' . $tax_term->slug . '">' . $tax_term->name.'</a></li>'; } ?> </ul> <ul class="display"> <?php // ADD PORTFOLIO $loop = new WP_Query(array('post_type' => 'portfolio', 'posts_per_page' => 6)); while ( $loop->have_posts() ) : $loop->the_post(); $custom = get_post_custom($post->ID); $screenshot_url = $custom["screenshot_url"][0]; $website_url = $custom["website_url"][0]; ?> <li class="<?php echo $tax_term->slug; ?> "> <a href="<?=$website_url?>"><?php the_post_thumbnail(); ?></a> <?php the_title(); ?> <?php the_content(); ?> <a href="<?=$website_url?>Learn more</a> </li> <?php endwhile; ?> </ul> Whats happening is that worpdress is repeating the last category slug on every display item... can anyone tell me what i have wrong here??? THANK YOU! Trisha Hi. I’m hoping someone can help me pull the styling/formatting from a static page onto a category template. The content is pulling fine, but it's not formatted/styled. Code used to pull content from static page onto custom category template: <?php $page = get_page_by_title( 'page-name' ); $content = apply_filters('the_content', $page->post_content); echo $content; ?> With the above code, the content is being pulled, but the formatting and styling is not being pulled. The following code is adapted to pull the styling/formatting: <?php $page = get_page_by_title( 'Wedding Venues in Costa Rica' ); $content = apply_filters('the_content', $page->post_content); echo do_blocks( $content );> It did not pull the styling/formatting. We’re using GeneratePress Pro + Generate Blocks (no page builder). The static page is built with Gutenberg and GenerateBlocks. By the way, I'mm not a coder or a developer. I know a little about this and about that, but this isn't my field of expertise. Could someone please suggest what can be done to this code to get it to pull the styling form the static page onto the custom category template? Thank you very much. I've a code that can create category if not existed the category & add this to the post. If category already exist then it will select the category. Here is my code snippet example : $mcptitle = 'Lenevo xiaoxin pad pro 2021'; //Geting Brand Name $brands = $mcptitle; $arr = explode(' ',trim($mcptitle)); $brand= $arr[0]; //Notice Brand name Detected //category Slug $catlink=sanitize_title($brand); //Finding category by name & geting id if($term = get_term_by( 'name', $brand, 'category' ) ){ $cat_id= $term->term_id; }else{ //creating category for not exists category $terms= wp_insert_term($brand, // the term 'category', // the taxonomy array( 'slug' => $catlink )); //geting new category id $cat_id= $terms['term_id']; //post start $post = array( 'post_author' => 1, 'post_content' => $content, 'post_status' => "publish", 'post_title' => $title, 'post_type' => "post", ); $post_id = wp_insert_post( $post, $wp_error ); //seting category wp_set_object_terms( $post_id, $cat_id, 'category' ); That works for create/add one category But I want to add multiple categories in it. Category array will be like this: $mcptitle = array("Volvo", "BMW", "Toyota"); Plz Can anyone help me about my thoughts. Thanks in advance. Hi everyone, newbie to site looking for help with my tag/category page formatting.
I recently bought a plugin for masonry and have been trying to make it the display for posts on my blog pages as you can see he http://www.enduringepilepsy.com/_blog/ and http://www.enduringe...m/archive/_2013
It's been helping my design and page load overall (Note: I do use Google Page Speed Service)
But I cannot figure out how to be able to use this customizable masonry for my tag/category pages since they do no show the ability to edit on the Wordpress admin bar.
I've looked at the php code in my files, and while I have become more familiar with php in the yr since I moved to Wordpress, am unsure how to edit these pages without making a mess.
The plugin is http://codecanyon.ne...-plugin/7563340 My theme, called Inzin, is no longer sold, and the developer disappeared from online. So I have lost all support. I would really appreciate any help anyone could offer. Thank you!
This topic has been moved to Microsoft SQL - MSSQL. http://www.phpfreaks.com/forums/index.php?topic=347695.0 I have multiple folders(domains) in my public_html folder. In my public_html folder i have a .htaccess file. I want to do mod rewrite on a specific domain e.g. www.test.com
Here is the mod rewrite wordpress has written for each domain
# BEGIN WordPress <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule> # END WordPressThe above code is in my .htaccess file multiple times, so i don't know which one to edit. I want to add the below code to the domain www.test.com but i don't know which one to edit. RewriteRule ^page/(.*) ads/page/$1 [R=301,L] RewriteRule ^page/(.*)/ ads/page/$1/ [R=301,L]What is the solution? Any help, greatly appreciated. This topic has been moved to PHP Applications. http://www.phpfreaks.com/forums/index.php?topic=333014.0 Hello, I have a website designed in simple php http://www.fsbizcollect.com/. It has a wordpress blog installed under sub-directory called "business-debt-collection-agency-blog" To query posts from blog on home page, I am using: <? foreach($sql->select("wp_posts", "where post_status = 'publish' order by post_date desc limit 3") as $row){ ?> <div class="bEntry"> <h2><?= $row['post_title'] ?></h2> <h3><?= date('F j, Y', strtotime($row['post_date'])) ?></h3> <p> <?= $row['post_excerpt'] ?> <a href="<?= $row['guid'] ?>">Read More</a></p> </div> <? } ?> It is working fine. I want to put post thumbnails on homepage. Post thumbnail should be automatically resized to width=110px and will be placed in : <div class="blogThumb"> POST THUMBNAIL PHP SCRIPT WILL COME HERE </div> Could anyone provide php script for this? Thank you This topic has been moved to PHP Applications. http://www.phpfreaks.com/forums/index.php?topic=348171.0 Currently I can use php snoopy class to auto login in wordpress, but when I try to use the same method to post some articles in wordpress. It does not work. Any one has any ideas? I have tried to use httpwatch to monitor the post data and cookies. It seems I have include everything, but still doesn't work. thanks very much. This really driving me crazy. <?php include "Snoopy.class.php"; $snoopy = new Snoopy; //login part $submit_url = "http://localhost/wordpress/wp-login.php"; $submit_vars["log"] = "baibai"; //username $submit_vars["pwd"] = "123456"; //password $submit_vars["rememberme"] = "forever"; $submit_vars["redirect_to"] = "http://localhost/wordpress/wp-admin/"; $submit_vars["testcookie"] = "1"; $submit_vars["wp_sumbit"] = "submit"; $snoopy->submit($submit_url,$submit_vars); print $snoopy->results; $snoopy->setcookies(); $cookies = $snoopy->cookies; print_r ($cookies); //above part runs perfectly //post $snoopy->fetchform("http://localhost/wordpress/wp-admin/press-this.php"); print $snoopy->results; preg_match('/name=\"_wpnonce\" value=\"([0-9a-z]+)/',$snoopy->results,$matches); print $submit_vars1["_wpnonce"] = $matches[1]; $submit_vars1["autosave"] = ""; $submit_vars1["newtag[post_tag]"] = ""; $submit_vars1["tax_input[post_tag]"] = ""; $submit_vars1["autosave"] = ""; $submit_vars1["title"] = "title"; $submit_vars1["content"] = "content this is what i want post in wordpress"; $submit_vars1["original_post_status"] = "draft"; $submit_vars1["prev_status"] = "draft"; $submit_vars1["post_type"] = "text"; $submit_vars1["publish"] = "发布"; $submit_vars1["_wp_http_referer"] = "/wordpress/wp-admin/press-this.php?u=http%3A%2F%2Flocalhost%2Fwordpress%2Fwp-admin%2Ftools.php&t=%E5%B7%A5%E5%85%B7%20%E2%80%B9%20ekeyvision%20%E2%80%94%20WordPress&s=&v=4"; $submit_url1 = "http://localhost/wordpress/wp-admin/press-this.php?action=post"; $snoopy->submit($submit_url1,$submit_vars1); print $snoopy->results; ?> Also I do not want to use XML-RPC to solve this issue, since xml-rpc are not available is some settings. thanks Hello all! So glad I found this forum. I would appreciate some assistance please. I'm working on a filter for a Custom Post Type . I need it to filter the list depending on the user's role. The way this should work is the following...
* Users in roles "formusers1" and "formusers2" can post. Users can only see their own posts. So far I can filter by roles "formusers1" and "formusers2" using `$query->set('author', $current_user->ID);` . However, when try to filter the list for role "formchecker1" I see posts from all roles. What am I doing wrong? Here's the rest of the code. Thanks for checking out!
```
function filter_posts_list($query) {
//MY VARIABLES
//FILTERING
if (current_user_can('formchecker2') && ('edit.php' == $pagenow) && $typenow == 'mycustomcpt' ) {
if ((current_user_can('formusers1') || current_user_can('formusers2')) && ('edit.php' == $pagenow) && $typenow == 'mycustomcpt') { I had a wordpress site setup for my maintenance company. I am not trying to setup a blog on the site. I have the blogroll showing up on this page: http://handymore.com/blog/ but when you click the individual articles the single post page shows a Error 404 message. Could anyone point me in the right direction as to how to fix this so that the individual post pages are found? Any guidance would be appreciated. Hello, Thanks for reading this. I'm working on a project where the homepage should be a Today's Deal and I'm using the Auto delete posts plugin to move the Today's Deal to the "Previous Deals" Category, after 24 hours. My task is to automatically redirect the homepage to the only post in Today's Deal Category, which will have different permalinks everyday. I'm querring the post with: <?php query_posts("cat=41&showposts=1"); ?> And I tried redirecting to the result with: <?php $url = the_permalink(); header("Location: $url"); ?> just after query_posts... but no success. I tried several other things too, apart from searching the web a lot before posting here. Help! Anyone? Thanks in advance! This topic has been moved to PHP Applications. http://www.phpfreaks.com/forums/index.php?topic=352987.0 Hello, I have been searching and trying all sorts of ways to get my sub categories drop down to show the correct info after selecting a category from the main drop down but im getting stuck. It's pulling the categories and sub categories from the mysql database fine but no matter which main category i pick it keeps showing the same result in the sub category. My brother said i need to use some sort of onchange do this so the sub category list refreshs but everything i have tried doesn't work.. PLEASE could some one help. MANY MANY THANKS This is the category form Code: [Select] <select name="job_cats" style="width:165px"> <?PHP $query1 = "SELECT * FROM job_cats"; $result1 = mysql_query($query1) or die ("query 1 failed"); $count1 = mysql_num_rows($result1); for ($i = 0; $i < $count1; $i++) { $row1 = mysql_fetch_array($result1); $job_cats_title1 = $row1['title']; $job_cats_id1 = $row1['id']; echo '<option value="'.$job_cats_id1.'">'.$job_cats_title1.'</option>'; echo $job_cats_id1; } ?> </select> this would echo this in the main category list: cat1 cat2 cat3 cat4 this is the sub category form Code: [Select] <select name="job_sub_cats" style="width:165px"> <?PHP $query1 = "SELECT * FROM job_sub_cats WHERE job_cats_id = $job_cats_id1"; $result1 = mysql_query($query1) or die ("query 1 failed"); $count1 = mysql_num_rows($result1); for ($i = 0; $i < $count1; $i++) { $row1 = mysql_fetch_array($result1); $sub_cats_id1 = $row1['id']; $sub_cats_title1 = $row1['subTitle']; $cats_id1 = $row1['job_cats_id']; echo '<option value="'.$sub_cats_id1.'">'.$cats_id1.'</option>'; } ?> </select> this should echo this: 1 2 3 4 but it keeps echoing just the number 4. THANKS PLEASE HELP ricky I want to pull some records plus unique key from one mysql table and then use them as questions in a form/questionnaire. The post form will have six radio buttons to the right of the fields pulled with the key posted but hidden and will wirte to another table. I guess this is a templating question- as I've successfully retrieved the table 1 records via a query - I just can't seem to use them in the form. Below is the code I'm using to view table "PCM1" <?php // query.php require_once 'login.php'; $db_server = mysql_connect($db_hostname, $db_username, $db_password); if (!$db_server) die("Unable to connect to MySQL: " . mysql_error()); mysql_select_db($db_database) or die("Unable to select database: " . mysql_error()); $query = "SELECT * FROM pcm1"; $result = mysql_query($query); if (!$result) die ("Database access failed: " . mysql_error()); $rows = mysql_num_rows($result); for ($j = 0 ; $j < $rows ; ++$j) { echo 'RID: ' . mysql_result($result,$j,'mcde') ; echo 'Statement: ' . mysql_result($result,$j,'oppclub') . '<br />'; ; } This topic has been moved to PHP Applications. http://www.phpfreaks.com/forums/index.php?topic=318539.0 I think I understand that there can only be one "submit" button on a page.
I want buttons for separate forms to not trigger the empty errors on the other forms...
How do you accomplish specific button actions?
I think I've tried it with javascript but you can do it with PHP right?
Thanks for any help.
I have a php tutorial that I followed for creating, inserting, selecting and updating a MySQL database with php. Everything works fine so I wanted to put it into Wordpress. I took the code and placed it into the wordpress page and everything worked just fine except the update function. Here is the tutorial I used. http://www.phpsimple.net/mysql_insert_record.html It is also the part I am having trouble with. I am able to create a record and I am also able to select a record but when I choose "update" the form doesn't load the data. It will outside the website but not inside wordpress. I am hoping this is not vague but because of my inexperience I am not sure what else to say. I will be more than happy to provide any other information you need. I use the Wholesale Suite Premium Prices plugin with WooCommerce. I have 6 specific wholesale roles out of 15 that I wish to hide two specific shipping methods from being selected for the 6 exceptions. I'm just trying this on my staging server at this time using a code snippet example that I found and modified for my specific conditions. Would the following work for this purpose? /* Hide specific shipping methods for specific wholesale roles */ add_filter( 'woocommerce_package_rates', function( $shipping_rates ) { // User role and shipping method ID to hide for the user role $role_shipping_method_arr = array( 'ws_silvia_silver' => array( 'Silvia Premium Standard Shipping (Tracking Service)'), 'ws_silvia_silver_pst_exempt' => array( 'Silvia Premium Standard Shipping (Tracking Service)'), 'ws_silvia_silver_tax_exempt' => array( 'Silvia Premium Standard Shipping (Tracking Service)'), 'ws_silvia_silver' => array( 'Silvia Union Standard Shipping (Tracking Service)'), 'ws_silvia_silver_pst_exempt' => array( 'Silvia Union Standard Shipping (Tracking Service)'), 'ws_silvia_silver_tax_exempt' => array( 'Silvia Union Standard Shipping (Tracking Service)'), 'ws_silvia_gold' => array( 'Silvia Premium Standard Shipping (Tracking Service)'), 'ws_silvia_gold_pst_exempt' => array( 'Silvia Premium Standard Shipping (Tracking Service)'), 'ws_silvia_gold_tax_exempt' => array( 'Silvia Premium Standard Shipping (Tracking Service)'), 'ws_silvia_gold' => array( 'Silvia Union Standard Shipping (Tracking Service)'), 'ws_silvia_gold_pst_exempt' => array( 'Silvia Union Standard Shipping (Tracking Service)'), 'ws_silvia_gold_tax_exempt' => array( 'Silvia Union Standard Shipping (Tracking Service)'), ); // Getting the current user role $curr_user = wp_get_current_user(); $curr_user_data = get_userdata($current_user->ID); // Wholesale Suite Roles if (isset($current_user) && class_exists('WWP_Wholesale_Roles')) { $wwp_wholesale_roles = WWP_Wholesale_Roles::getInstance(); $wwp_wholesale_role = $wwp_wholesale_roles->getUserWholesaleRole(); // Loop through the user role and shipping method pair foreach( $role_shipping_method_arr as $role => $shipping_methods_to_hide ) { // Check if defined role exist in current user role or not if( in_array( $role, $current_user->roles) ) { // Loop through all the shipping rates foreach( $shipping_rates as $shipping_method_key => $shipping_method ) { $shipping_id = $shipping_method->get_id(); // Unset the shipping method if found if( in_array( $shipping_id, $shipping_methods_to_hide) ) { unset($shipping_rates[$shipping_method_key]); } } } } } return $shipping_rates; }); Any insights as to how to accomplish this would be greatly appreciated. Lyse |