草庐IT

named-query

全部标签

php - query_posts() 应该避免吗?

我读到应该避免使用query_posts(),而使用wp_query()和pre_get_posts()。我对弄乱循环没有信心,也不完全理解法典。下面的代码是否使用了query_posts()?如果是,并且由于应避免使用query_posts(),您能否建议一种不使用query_posts()但仍能完成相同事情的方法?functions.php中的这段代码用于按随机或按价格对帖子进行排序。functionmy_custom_query($query){if($query->is_home()&&$query->is_main_query()){$sort=$_GET['sort'];i

php - vTiger 网络服务 : Permission to perform the operation is denied for query

我正在使用vTigerWeb服务通过查询检索包含我的联系人的VtigerObjects数组。我正在按照此处给出的说明进行操作:https://wiki.vtiger.com/index.php/Webservices_tutorials到目前为止,我得到了一个可以用来登录的质询token,所以这是有效的。但是从我尝试通过查询获取数据的那一刻起,我收到以下错误:“查询执行操作的权限被拒绝”我是管理员,所以我应该拥有所有权限,对吗?这是我的代码,希望有人能帮助我?$username='xxxxxxxxxx';$userAccessKey='xXxXxXxXxXxXxX';//CreateH

php - Wordpress WP_Query/get_posts where post_title equals 返回所有结果

我创建了一个名为“片段”的自定义帖子类型,其中包含客户可以更改的数据片段,例如“地址”。片段的标题都是唯一的:我创建了一个简单的函数来返回这些片段,但它运行不正常,我不确定为什么。功能:functionget_snippet($snippet_title){$snippet_page=newWP_Query(array('post_type'=>'snippets','post_title'=>$snippet_title));return$snippet_page->posts[0]->post_content;}下面是一个函数调用示例:echoget_snippet('footer

php - 具有待定状态问题的 WP_Query 和 WooCommerce 订单

我无法获得状态为wc-pending/PendingPayment的订单对象。它只是返回所有订单对象:$my_course_query=newWP_Query(array('post_type'=>'shop_order','post_status'=>'wc-pending','posts_per_page'=>-1)); 最佳答案 YourcodeIsjustworkingperfectlyasexpected,infrontend,Ihavetestitanditoutputonlyorderswith**pendingsta

php - 在 Woocommerce 的 WP_Query 循环中显示产品价格

我有这个代码来显示某个类别的产品,我还想显示它的价格。有什么我可以添加或更改的想法吗?下面的代码不显示任何内容(也没有错误)。'product','post_status'=>'publish','posts_per_page'=>10,'tax_query'=>array(array('taxonomy'=>'product_cat','field'=>'slug','terms'=>$product_categories,'operator'=>'IN',))));?>CatNamehave_posts()):?>have_posts()):$wc_query->the_post(

PHP 7.2.7 : Attempted to call an undefined method named "setEncryptionName" of class "ZipArchive"

我正在尝试使用PHP7.2.7创建一个加密的、受密码保护的ZIP文件。但是,我收到以下错误消息:Attemptedtocallanundefinedmethodnamed"setEncryptionName"ofclass"ZipArchive".http://php.net/manual/en/ziparchive.setencryptionname.php如果我删除$zip->setEncryptionName()那么一切都会100%,除了ZIP文件没有密码保护。我在Google和论坛上进行了搜索,但找不到遇到过类似问题的人,可能是因为PHP版本和功能仍然太新。

php array_filter function not found or invalid function name 不管我输入什么

我之前从未使用过array_filter函数,所以无论我使用什么作为函数名称,它都会给我错误,请尝试一下Warning:array_filter()expectsparameter2tobeavalidcallback,function'odd'notfoundorinvalidfunctionnamein我什至采取了直接从php手册页复制粘贴示例的步骤,它给了我同样的错误。代码:functionodd($var){//returnswhethertheinputintegerisoddreturn($var&1);}functioncalculate($res,$period,$el

PHP 文件上传 : keep both files if same name

在PHP中是否有任何漂亮的解决方案允许我在文件名已经存在的情况下使用自动递增数字扩展文件名?我不想在一些不可读的东西中重命名上传的文件。所以我认为这样会很好:(允许所有图像文件。)Cover.pngCover(1).pngCover(2).png… 最佳答案 首先,让我们分开扩展名和文件名:$file=pathinfo();为了便于文件检查和追加,将文件名保存到新变量中:$filename=$file['filename'];然后,让我们检查文件是否已经存在并保存新的文件名,直到它不存在为止:$i=1;while(file_exis

PHP [QUERY_STRING] 在回车处被截断

关于SO的第一个问题!我在apache2.2.22上运行PHP5.3.10。我只是这样做:Apache的error.log中的输出如下:Array([HTTP_HOST]=>dns1[PATH]=>/usr/local/bin:/usr/bin:/bin[SERVER_SIGNATURE]=>Apache/2.2.22(Ubuntu)Serveratdns1Port80[SERVER_SOFTWARE]=>Apache/2.2.22(Ubuntu)[SERVER_NAME]=>dns1[SERVER_ADDR]=>192.168.2.6[SERVER_PORT]=>80[REMOTE_

php - 编译失败 : unknown property name after\P or\p

您好,我想匹配一个字符串:“\parhello\parworld”针对我的正则表达式模式->\\par但是,我得到一个Compilationfailed:unknownpropertynameafter\Por\p我相信我的正则表达式规则被视为unicode字符属性。我如何转义它并按原样运行模式?我像这样将它包含在PDO函数中。functionsqlite_regExp($sql,$db){if($db->sqliteCreateFunction("regexp","preg_match",2)===FALSE)exit("Failedcreatingfunction!");if($r